python 类实例化,修改属性值

class User(object):
def __init__(self, first_name, last_name, login_attempts):
self.first_name = first_name
self.last_name = last_name
self.login_attempts = login_attempts def increment_login_attempts(self, miles):
'''递增'''
self.login_attempts += miles def reset_login_attempts(self):
'''重置'''
self.login_attempts = 0 def read_login_attempts(self):
'''打印'''
print self.first_name + ' ' + self.last_name + ' ' + 'this is ' + str(self.login_attempts) user = User('xiao', 'ming', 5)
user.increment_login_attempts(10)
user.read_login_attempts() user.increment_login_attempts(10)
user.read_login_attempts() user.increment_login_attempts(10)
user.read_login_attempts() user.reset_login_attempts()
user.read_login_attempts()
上一篇:Java HashMap 如何正确遍历并删除元素


下一篇:shell字符串和数组