Commit 530e8812 by BellCodeEditor

save project

parent 70850cf8
Showing with 9 additions and 0 deletions
class Hero:#定义一个类 class 类名:
    def __init__(self,name,hp,attack):#多加几个形参
        self.level = 1#定义形参,定义成自己
        self.hp = hp
        self.attack = attack
yase = Hero("亚瑟",300,40)#name是"亚瑟",hp,attack是300,40
houyi = Hero("后羿",300,40)#按def __init__的方法里形参的顺序挨个写具体值(实参)
print(yase)#打印yase的参数。可以直接打印
print(houyi)
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