我是靠谱客的博主 发嗲山水,这篇文章主要介绍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()

转载于:https://www.cnblogs.com/jinbaobao/p/9924084.html

最后

以上就是发嗲山水最近收集整理的关于python 类实例化,修改属性值的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部