|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class User():
def __init__(self,first_name,last_name,age,height):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.height = height
self.login_attempts = 0
def describe_user(self):
name = ("name=" + self.first_name + self.last_name + "\nage=" + str(self.age) + "\nheight=" + str(self.height) + "cm")
return name.title()
def greet_user(self):
print(self.first_name + self.last_name + "Hello!")
def increment_login_attempts(self,one):
self.login_attempts += 1
def reset_login_attempts(self,zero):
self.login_attempts = zero
def print_login_attempts(self):
print("Attempt number " + str(self.login_attempts))
Family_user = User("sun","shan",25,183)
Family_user.increment_login_attempts()
Family_user.print_login_attempts()
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\110.py", line 29, in <module>
Family_user.increment_login_attempts()
TypeError: increment_login_attempts() missing 1 required positional argument: 'one'
问题:我想递增加1 这里不懂怎么操作了
你是想要一个和具体实例化无关的计算变量吗?
可以将这个函数声明为@staticmethod 或者 @classmethod
然后直接用类名调用即可
详细你可以百度一下
|
|