Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9ffac3fb
authored
Oct 26, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
852fbb51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
P1-14.py
P1-14.py
0 → 100644
View file @
9ffac3fb
# 类与对象一
# 什么是类? 具有相同特征、特征、功能或行为的对象归为一类
# 对象是类的实例化(具体的个体)
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment