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 shot(self): print("shooting...") def got_shot(self): print("ah...,I got shot...") def buy_gun(self,gun_name): print("just bought %s" %gun_name)r1 = Role('Alex','police','AK47’) #生成一个角色r2 = Role('Jack','terrorist','B22’) #生成一个角色#
__init__ 调用这个类传参用的
1.把一个类变成一个对象的过程叫实例化

浙公网安备 33010602011771号