Commit 9ffac3fb by BellCodeEditor

auto save

parent 852fbb51
Showing with 35 additions and 0 deletions
# 类与对象一
# 什么是类? 具有相同特征、特征、功能或行为的对象归为一类
# 对象是类的实例化(具体的个体)
# class 定义类
# class 类名: # class 类名(): 小括号没有特殊情况可以省略
# 类名定义方法
# 1.类名后需要加英文冒号
# 2.定义类使用关键字class是小写
# 3.命名规则由数字、字母或者下划线组成,不能由数字开头,不能使用关键字
# 驼峰命名法由单词组成,每个单词首字母大写
# __init__(类属性)
# class 类名:
# def__init__(self):
# self.变量1 = 属性1 #类属性
# self.变量1 = 属性1 #类属性
class Hero:
def __init__(self):
self.level = 1
self.hp = 100
self.attact = 20
# yase = Hero() # 调用类 变量名 = 类名()
# print(yase.level) # 查看类属性 变量名.类属性
# 定义类&实例化对象
zzn = Hero()
print('宝贝的等级是:'zzn.level)
print('宝贝的血量是:'zzn.hp)
print('宝贝的攻击力是:'zzn.attact)
\ 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