class Role(object):
#定义一个类,class是定义类的语法,Role是类名,(object)是新式类的写法
def _init_(self,name,role,weapon ,life_value):#初始化函数,
self.name=name
self.role=role
self.weapon=weapon
self.life_value=life_value
def shot(self):
print("shooting....")
def got_shot(self):
print("i got shot....")
def buy_gun(self,gun_name):
print("%s just bought [%s] "%(self .name,gun_name))
self.weapon=gun_name
r1=Role("Alex",'police',"AK47",90)
r1.buy_gun("AK47")
r2=Role("jack",'terrorist',"B22",100)
r2.buy_gun("B51")
print("r1:",r1.buy_gun())
print("r2:",r2.buy_gun())