摘要: # # # 姓名:王飞 年龄:30 性别:男 工龄:5 # # 我承诺,我会认真教课。 # # 王飞爱玩象棋 # # # # 姓名:小明 年龄:15 性别:男 学号:00023102 # # 我承诺,我会 好好学习。 # # 小明爱玩足球。 # # # # 案例题目描述: # # 从案例效果分析有老师和学生2个事物,老师里面有姓名、年龄、性别、工龄几个变量。 # # 学生里面有姓名、年龄、性别、... 阅读全文
posted @ 2018-12-21 22:19 青春叛逆者 阅读(201) 评论(0) 推荐(0) 编辑
摘要: #创建一个炮台类 attaction=0 class Paota: #初始化函数 def __init__(self,name,attaction): self.name=name self.attaction=attaction def attack(self): print("%s建设完毕,攻击力%d,"%(self.n... 阅读全文
posted @ 2018-12-21 22:13 青春叛逆者 阅读(328) 评论(0) 推荐(0) 编辑
摘要: class Admin: def __init__(self,name,passwd): self.name=name self.passwd = passwd def login(self,): name=input("请输入管理员账户:") passwd=input("请输入管理员密码:") i 阅读全文
posted @ 2018-12-21 22:11 青春叛逆者 阅读(1415) 评论(0) 推荐(0) 编辑
摘要: ''' 了解 当对象销毁的时候自动执行 对象销毁的时机: 1.del手动销毁 2.当程序结束自动销毁 3.覆盖 4.在函数中为局部变量的时候 ''' class Person: def __init__(self): print("我出生了") def __del__(self): print("再见") d... 阅读全文
posted @ 2018-12-21 22:03 青春叛逆者 阅读(262) 评论(0) 推荐(0) 编辑
摘要: ''' __str__():当打印对象名的时候自动执行 要求:必须return字符串 ''' class Person: def __init__(self): self.name = None self.age = None def __str__(self): return "姓名:%s,年龄:%d"%(self.nam... 阅读全文
posted @ 2018-12-21 22:00 青春叛逆者 阅读(149) 评论(0) 推荐(0) 编辑
摘要: ''' 访问限制:限制别人调用某一些属性或者函数 好处:提高代码的安全性 做法:在名字前面加2个下划线__ 如果要赋值或者访问就必须提供setXXX或者getXxx函数 ''' class Person: def __init__(self): self.name=None self.__age=None def setAge(self,age):... 阅读全文
posted @ 2018-12-21 21:58 青春叛逆者 阅读(184) 评论(0) 推荐(0) 编辑
摘要: class Person: # def __init__(self,x,y,z): # self.name=x # self.age=y # self.sex=z # print("我出生了,我的名字是:%s,年龄是:%d,性别是:%s" # %(self.name,self.age,self.s... 阅读全文
posted @ 2018-12-21 21:56 青春叛逆者 阅读(230) 评论(0) 推荐(0) 编辑
摘要: class Cat: def __init__(self): # 构造函数(属性有 姓名 年龄 颜色) self.name = None self.age = None self.color = None def run(self): print("%s在跑步"%self.name) def crow(se... 阅读全文
posted @ 2018-12-21 21:55 青春叛逆者 阅读(207) 评论(0) 推荐(0) 编辑
摘要: class Cat: def __init__(self,name=None,age=None,color=None): self.__name=name self.__age=age self.__color=color def setName(self,name): self.__name=name ... 阅读全文
posted @ 2018-12-21 21:54 青春叛逆者 阅读(302) 评论(0) 推荐(0) 编辑
摘要: ''' 2只手交换牌 人: 属性:左手 右手 行为:交换 手: 属性:牌 行为: 牌: 属性:花色和数字 行为: ''' class Person: def __init__(self): self.left=None self.right=None def change(self): ... 阅读全文
posted @ 2018-12-21 21:52 青春叛逆者 阅读(152) 评论(0) 推荐(0) 编辑