Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson14_1
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
a2cc0669
authored
Apr 23, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
f47689a4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
0 deletions
diy.py
diy1.py
diy2.py
diy3.py
diy.py
View file @
a2cc0669
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
diy1.py
0 → 100644
View file @
a2cc0669
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
diy2.py
0 → 100644
View file @
a2cc0669
diy3.py
0 → 100644
View file @
a2cc0669
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