1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#方式一
class
A():
def
__init__(
self
, name):
self
.name
=
name
print
(
"a class ..."
)
class
B():
def
__init__(
self
, age):
self
.age
=
age
print
(
"b class..."
)
class
Sub(A, B):
def
__init__(
self
, name, age, phone):
A.__init__(
self
, name)
B.__init__(
self
, age)
self
.phone
=
phone
print
(
"sub class..."
)
def
get_all_info(
self
):
print
(
self
.name,
self
.age,
self
.phone)
if
__name__
=
=
'__main__'
:
s
=
Sub(
"toby"
,
25
,
110
)
s.get_all_info()
#方式二
class
A():
def
__init__(
self
, name):
self
.name
=
name
print
(
"a class ..."
)
class
B(A):
def
__init__(
self
, name, age):
super
(B,
self
).__init__(name)
self
.age
=
age
print
(
"b class..."
)
class
Sub(B):
def
__init__(
self
, name, age, phone):
super
(Sub,
self
).__init__(name, age)
self
.phone
=
phone
print
(
"sub class..."
)
def
get_all_info(
self
):
print
(
self
.name,
self
.age,
self
.phone)
if
__name__
=
=
'__main__'
:
s
=
Sub(
"toby"
,
25
,
110
)
s.get_all_info()
|
本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/2058629