Commit fc1d1b6c by BellCodeEditor

auto save

parent 6c0b0cc3
Showing with 29 additions and 9 deletions
class Hero(): class Hero:
def __init__(self): #默认函数
self.level = 1 def __init__(self,level,hp,attack):
self.hp = 300 self.level = level
self.attack = 20 self.hp=hp
self.attack=attack
yase = Hero()
print(yase.hp) def up(self):
\ No newline at end of file self.level = self.level+1
self.hp =self.hp+40
self.attack =self.attack + 20
yase = Hero(1,300,20)
libai = Hero(2,200,50)
dufu = Hero(3,100,100)
yase.up()
libai.up()
#定义函数
#p 形式参数
def a(p):
p = p + 1
return p
#调用函数 函数名加括号
#1 实际参数
z = a(1)
print(z)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment