部分源代碼:
報錯:
TypeError: can only concatenate str (not “list”) to str
類型錯誤:隻能連接配接str(不是“清單”)到str
debug操作:str()類型轉換
class User:
"""表示一個簡單的使用者配置檔案。"""
def __init__(self, first_name, last_name, username, email, location): # location表位置
"""初始化使用者"""
self.first_name = first_name
self.last_name = last_name
self.username = username
self.email = email
self.location = location
self.login_attemps = 0
def describe_user(self):
"""顯示使用者資訊的摘要"""
print("\n" + self.first_name + " " + self.last_name)
print(" Username: " + self.username)
print(" Email: " + self.email)
print(" Location: " + self.location)
def greet_user(self):
"""向使用者顯示個性化的問候"""
print("\n Welcome back, " + self.username + "!")
def increment_login_attmpts(self):
"""增加登入嘗試的值"""
pass
def reset_login_attempts(self):
"""重置登入嘗試為0"""
pass
class Admin(User):
"""具有管理權限的使用者。"""
def __init__(self, first_name, last_name, username, email, location):
# super()
"""初始化管理。"""
super().__init__(first_name, last_name, username, email, location)
self.privileges = []
# privileges表示權力
def show_privileges(self):
"""顯示此管理者擁有的特權"""
print("管理者的權力有:" + str(self.privileges))
shi_li = Admin("楊", "錢生", "Administrator", "[email protected]", "上海")
shi_li.privileges = ["可建立檔案","可删除使用者","可以禁止使用者的權限"]
shi_li.describe_user()
shi_li.show_privileges()