博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建一个名为User的类
阅读量:4709 次
发布时间:2019-06-10

本文共 1116 字,大约阅读时间需要 3 分钟。

# -*- conding:utf-8 -*-class User:    def __init__(self,first_name,last_name,age,sex,phone,login_attempts = 0):        self.first_name = first_name        self.last_name = last_name        self.age = age        self.sex = sex        self.phone = phone        self.login_attempts=login_attempts    def describe_user(self):        print('我叫 %s  %s,今年%d岁,我的电话是%s'%(self.first_name,self.last_name,self.age,self.phone))    def greet_user(self):        print('尊敬的%s,您好!'%self.first_name)     #递增登录次数    def increment_login_attempts(self):        self.login_attempts += 1        print('%s的登录次数为:%d'%(self.first_name,self.login_attempts))     #重置登录次数    def reset_login_attempts(self):        self.login_attempts = 0        print('%s的登录次数为:%d' % (self.first_name, self.login_attempts))if __name__ == '__main__':    joe = User('Joe','Black',20,'男','18011123333')    #joe.describe_user()    # joe.greet_user()    joe.increment_login_attempts()    joe.increment_login_attempts()    joe.increment_login_attempts()    joe.increment_login_attempts()    joe.reset_login_attempts()

 

转载于:https://www.cnblogs.com/xyg-zyx/p/8884364.html

你可能感兴趣的文章
2012/11/14第一次真正加入博客园
查看>>
laravel页面间的传值
查看>>
SoapUI登录测试(2)-- 断言
查看>>
ORM是什么?
查看>>
冒泡排序---程序员必经之路
查看>>
jenkins构建执行shell 所有命令出现command not found
查看>>
Nginx的HTTPS 301重定向到另一个TLD(托管在同一服务器上)没有显示出SSL警告
查看>>
RUBY 模拟rtsp消息
查看>>
spring与axis2整合发布webservice
查看>>
A - Financial Management(1.1.1)
查看>>
先注册,再登录(简易版)
查看>>
Java多线程通讯---------wait,notify区别
查看>>
spring.xml配置
查看>>
P1855 榨取kkksc03
查看>>
.net转java 学习笔记 (一) java环境安装和配置
查看>>
浅谈window.attachEvent
查看>>
聚类算法——KMEANS算法
查看>>
【Java】 Thinking in Java 2-11 练习10
查看>>
26. Remove Duplicates from Sorted Array
查看>>
JavaScript要点(十二) HTML DOM 事件
查看>>