class User():
def init(self, first_name, last_name, others):
self.first_name = first_name
self.last_name = last_name
self.others = others
self.login_attempts = 0
def describe_user(self):
print("This is the basic information: "
+ self.first_name)
def greet_user(self):
print("Hello, " + self.first_name + self.last_name +
"\nyour information is " + self.others)
def increment_login_attempts(self):
self.login_attempts += 1
return self.login_attempts
def reset_login_attempts(self):
self.login_attempts = 0
U1 = User('Liu', 'Bw','eerdos')
U1.increment_login_attempts()
print(self.login_attempts)
class User(object):
def __init__(self, first_name, last_name, others):
self.first_name = first_name
self.last_name = last_name
self.others = others
self.login_attempts = 0
def describe_user(self):
print("This is the basic information: "
+ self.first_name)
def greet_user(self):
print("Hello, " + self.first_name + self.last_name +
"\nyour information is " + self.others)
def increment_login_attempts(self):
self.login_attempts += 1
return self.login_attempts
def reset_login_attempts(self):
self.login_attempts = 0
if __name__ == '__main__':
U1 = User('Liu', 'Bw', 'eerdos')
print('Now, the number is ' + str(U1.increment_login_attempts()))
U1.increment_login_attempts()
# 这里不能用self,要用U1,你实例化的对象是U1,self只在类内部使用,外部使用需要实例化对象.属性或函数(方法)
print(U1.login_attempts)