我遇到一个错误:“ tuple”对象的以下代码没有属性“ first_name”。我完全被困住了
class User:
"""Summarizes User Profile"""
def __init__(self,first_name, last_name, followers, following):
self.first_name = first_name
self.last_name = last_name
self.followers = followers
self.following = following
self.fullname = first_name + " " + last_name
def describe_user(self):
print(self.fullname + " has " + followers + " and follows " + following + " users")
def greet_user(self):
"""Greets user"""
print("Welcome back, " + self.fullname)
#User info
user1 = ("Krish","Patel",100, 200)
user2 = ("Bob","Smith",2032, 153)
User.describe_user(user1)
答案 0 :(得分:0)
您实际上需要实例化一个User
对象,而不仅仅是一个tuple
。试试
user1 = User("Krish","Patel",100, 200)
user2 = User("Bob","Smith",2032, 153)