Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_4
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
5ed03936
authored
Jan 17, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
22354288
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
ui.py
ui.py
0 → 100644
View file @
5ed03936
class
Hero
:
# 定义类
def
__init__
(
self
,
name
,
hp
,
attack
):
# 构造函数(主要是初始化属性)
self
.
level
=
1
self
.
name
=
name
# name:名字
self
.
hp
=
hp
self
.
attack
=
attack
# attack:攻击
def
upgrade
(
self
):
# 升级功能
self
.
level
=
self
.
level
+
1
self
.
hp
=
self
.
hp
+
50
self
.
attack
=
self
.
attack
+
4
houyi
=
Hero
(
"后羿"
,
240
,
23
)
# 实例化对象
houyi
.
upgrade
()
# 对实例化对象使用升级功能
print
(
"等级为:"
,
houyi
.
level
)
print
(
"血量为:"
,
houyi
.
hp
)
print
(
"攻击力为:"
,
houyi
.
attack
)
'''
今天的学习目标是认识类和对象之间的关系:类(群体、种类);对象(个体,一个类里面的具体实例);掌握
类的定义方式;掌握构造函数__init__()方法;掌握定义实例方法的方式;这节课的内容跟前面的课程的内容
差距比较大,因为类和对象是一个抽象的概念,所以需要好好思考和理解类和对象的关系,类属性和实例属性的区别,还有就是self参数的作用。
'''
\ 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