python 内置函数
class Role(object): def __init__(self, name, role, weapon, life_value=100, money=15000):#内置函数,程序启动自动调用 self.name = name self.role = role self.weapon = weapon self.__life_value = life_value#私有属性,外部无法调用和访问 self.money = money def __del__(self):#析构函数,在实例释放、销毁的时候自动调用,通用用于做一些收尾工作 print(‘%s 彻底嗝屁了‘%self.name) def __shot(self):#私有方法,外部无法调用和访问 print("shooting...") def got_shot(self): print("ah...,I got shot...") def buy_gun(self, gun_name): print("%s just bought %s" % (self.name,gun_name))r1 = Role(‘Alex‘, ‘police‘, ‘AK47‘) #实例化(初始化一个类,造一个对象)r2 = Role(‘Jack‘, ‘terrorist‘, ‘B22‘) #生成一个角色r1.buy_gun(‘AK47‘)
相关推荐
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
FlySky 2020-11-02
逍遥友 2020-10-26
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26