Commit a2cc0669 by BellCodeEditor

auto save

parent f47689a4
Showing with 22 additions and 0 deletions
class Hero: # 类名,Hero表示英雄
def __init__(self): # 用关键字def定义一个 __init__方法,参数:(self)
self.level = 1 # 等级
self.hp = 300 # 生命(类属性)
self.attack = 20 # 攻击力(类属性)
yase = Hero() # 将Hero()这个类赋值给变量yase
print(yase.hp) # 打印出生命
print(yase.attack) # 打印出攻击力
\ No newline at end of file
class Hero: # 类名,Hero表示英雄
def __init__(self, name, hp, attack): # 用关键字def定义一个 __init__方法,参数:(self)
self.level = 1 # 等级
self.name = name # 名字(类属性)
self.hp = hp # 生命(类属性)
self.attack = attack # 攻击力(类属性)
yase = Hero("亚瑟",300,20)
houyi = Hero("后羿",240,23)
print("亚瑟的血量为: ",yase.hp)
print("后羿的血量为: ",houyi.hp)
\ 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