储存User类的模块user
class User(): def __init__(self, first_name, last_name, address): self.first_name = first_name self.last_name = last_name self.address = address def describe_user(self): print('First name: ' + self.first_name.title()) print('Last name: ' + self.last_name.title()) print('Address: ' + self.address.title()) def greet_user(self): self.full_name = self.first_name.title() + ' ' + self.last_name.title() print("Welcome come to enjoy us, " + self.full_name.title() + "!")
储存Admin和Privileges的模块privileges_admin
from user import User #引入模块user中的User类 class Admin(User): def __init__(self , first_name , last_name , address): super().__init__(first_name , last_name , address) self.privileges = Privileges() #9-8 class Privileges(): def __init__(self): self.priviliges = ['can add post', 'can delete post', 'can ban user'] def show_privileges(self): for n in self.priviliges: print("This admin " + n)
9-12的代码
from privileges_admin import Admin, Privileges z = Admin('li', 'ming', 'xian') z.privileges.show_privileges()
结果
This admin can add post
This admin can delete post
This admin can ban userProcess finished with exit code 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)