python: multiple inheritance

多继承:

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:21
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Father.py
# explain   : 学习
import sys
import os
 
 
class Father(object):
    """
    父类
    """
    def __init__(self, money):
        self._money = money
 
    @property
    def Money(self):
        """
        财富
        :return:
        """
        return self._money
 
    @Money.setter
    def Money(self, money):
        """
        财富
        :param money:
        :return:
        """
        self._money = money
 
 
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:18
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Mother.py
# explain   : 学习
 
 
import os
import sys
 
 
class Mother(object):
    """
    母类
    """
    def __init__(self, faceValue):
        """
 
        :param faceValue: 颜值
        """
        self._facevalue = faceValue
 
    @property
    def FaceValue(self):
        """
        颜值
        :return:
        """
        return self._facevalue
 
    @FaceValue.setter
    def FaceValue(self, facevalue):
        """
        颜值
        :param facevalue:
        :return:
        """
        self._facevalue = facevalue
 
 
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:22
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Son.py
# explain   : 学习
 
import os
import sys
import Father
import Mother
 
 
class Son(Father.Father, Mother.Mother):
    """
    儿子继承父类和母类
    多继承
    """
 
    def __init__(self, money: str, faceValue: str, work: str):
        """
        多继承的用法
        :param money:
        :param faceValue:
        :param work:
        """
        self._work = work
        Father.Father.__init__(self, money)
        Mother.Mother.__init__(self, faceValue)
 
    @property
    def Work(self):
        """
        个性
        :return:
        """
        return self._work
 
    @Work.setter
    def Work(self, work):
        """
        个性
        :param work:
        :return:
        """
        self._work = work
 
    def Personality(self):
        """
        显示各特性的方法
        :return:
        """
        print(f"儿类的个性有:父的[{self.Money}]母的[{self.FaceValue}]自身变异特有的[{self._work}]")

  

调用:

1
2
3
print_hi('PyCharm,Geovin Du,涂聚文')
sn=Son.Son("财富","颜值","帅气");
sn.Personality()

  

输出:

1
2
Hi, PyCharm,Geovin Du,涂聚文
儿类的个性有:父的[财富]母的[颜值]自身变异特有的[帅气]

  

 另一写法多继承,一样作用:

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:21
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Father.py
# explain   : 学习
import sys
import os
 
 
class Father(object):
    """
    父类
    """
    def __init__(self): #, money
        self._money = ""
 
    @property
    def Money(self):
        """
        财富
        :return:
        """
        return self._money
 
    @Money.setter
    def Money(self, money):
        """
        财富
        :param money:
        :return:
        """
        self._money = money
 
 
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:18
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Mother.py
# explain   : 学习
 
 
import os
import sys
 
 
class Mother(object):
    """
    母类
    """
    def __init__(self):#, faceValue
        """
 
        :param faceValue: 颜值
        """
        self._facevalue = ""
 
    @property
    def FaceValue(self):
        """
        颜值
        :return:
        """
        return self._facevalue
 
    @FaceValue.setter
    def FaceValue(self, facevalue):
        """
        颜值
        :param facevalue:
        :return:
        """
        self._facevalue = facevalue
 
 
# encoding: utf-8
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 11
# Datetime  : 2023/7/3 14:22
# User      : geovindu
# Product   : PyCharm
# Project   : pythonProject
# File      : Son.py
# explain   : 学习
 
import os
import sys
import Father
import Mother
 
 
class Son(Father.Father, Mother.Mother):
    """
    儿子继承父类和母类
    多继承
    """
 
    def __init__(self): #, money: str, faceValue: str, work: str
        """
        多继承的用法
        :param money:
        :param faceValue:
        :param work:
        """
        self._work =""
        Father.Father.__init__(self)
        Mother.Mother.__init__(self)
 
    @property
    def Work(self):
        """
        个性
        :return:
        """
        return self._work
 
    @Work.setter
    def Work(self, work):
        """
        个性
        :param work:
        :return:
        """
        self._work = work
 
    def Personality(self):
        """
        显示各特性的方法
        :return:
        """
        print(f"儿类的个性有:父的[{self.Money}]母的[{self.FaceValue}]自身变异特有的[{self._work}]")

  

 调用:

1
2
3
4
5
6
print_hi('PyCharm,Geovin Du,涂聚文')
sn=Son.Son();#"财富","颜值","帅气"
sn.Money="财富"
sn.FaceValue="颜值"
sn.Work="帅气"
sn.Personality()

  

输出:

1
2
Hi, PyCharm,Geovin Du,涂聚文
儿类的个性有:父的[财富]母的[颜值]自身变异特有的[帅气]

  

 

 

 

单继承:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Gold(object):
    """
 
    """
    def __init__(self,name:str,color:str):
        self._name=name
        self._color=color
 
    def intrudce(self):
        print(f"")
 
import Gold
 
 
class GoldPear(Gold.Gold):
 
    def __init__(self,name:str,color:str,category:str):
        super().__init__(name,color)
        self._category=category

  

 

posted @   ®Geovin Du Dream Park™  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2010-07-02 SQL server查询数据类型为ntext是空或NULL值
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示