Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
0
05_homework_daxiong
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
大雄
05_homework_daxiong
Commits
bbc8b132
Commit
bbc8b132
authored
Feb 05, 2019
by
大雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
课堂内容
parents
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
why_integration.py
+49
-0
No files found.
why_integration.py
0 → 100644
View file @
bbc8b132
class
Person
:
#这里Person后面要有冒号
name
=
"女娲"
age
=
10000
__school
=
"class private school"
def
__init__
(
self
,
name
,
age
,
home
):
#只能写一个构造函数
self
.
name
=
name
self
.
age
=
age
self
.
__home
=
home
print
(
"有参数的构造函数运行"
)
#实例方法
def
my_print
(
self
):
print
(
"my print run"
)
#私有方法
#只能允许这个类本身进行访问,连子类也不可以访问
def
__creat_person
(
self
):
#后面要有(self):
print
(
"私有方法——女娲创造了一个人"
)
#保护方法
#保护类型权限允许类本身和子类进行访问
def
_my_protect_print
(
self
):
print
(
"ssss"
)
@classmethod
#classmethod的位置有讲究,放到p = Person()后面就不对
def
my_classmethod
(
cls
,
p
):
print
(
cls
.
name
)
print
(
p
.
name
)
print
(
"classmethod——类方法运行"
)
# p = Person("张三", "20", "家") #这里在Person后面要有括号()
# p = Person() #当有多个构造函数的时候,无参数的构造函数不起作用
"""
函数:在模块中声明的一般叫做函数
方法:在类中声明的叫做方法
"""
p
=
Person
(
"伏羲"
,
"15000"
,
"家"
)
p
.
my_classmethod
(
p
)
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