天天看点

TypeError: can only concatenate str (not “list“) to str(列表和字符串的报错解决方法)

部分源代码:

TypeError: can only concatenate str (not “list“) to str(列表和字符串的报错解决方法)

报错:

TypeError: can only concatenate str (not “list”) to str

类型错误:只能连接str(不是“列表”)到str

debug操作:str()类型转换

TypeError: can only concatenate str (not “list“) to str(列表和字符串的报错解决方法)
TypeError: can only concatenate str (not “list“) to 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()