‘’‘子类继承父类’’’
```python
class Frute(object):
def __init__(self,name):
self.name=name
def info(self):
print("u'水果的名字是:{0}".format(self.name))
class Apple(Frute):
def __init__(self,name,brand,color):
Frute.__init__(self,name)
self.brand=brand
self.color=color
def info(self):
print("水果是{0},品牌是{1},颜色是{2}".format(self.name,self.brand,self.color))
f1=Apple("苹果","红富士","红色")
f1.info()
C:\Programs\Python\Python35\python.exe D:/script/myobj.py
水果是苹果,品牌是红富士,颜色是红色
Process finished with exit code 0
```python
```python
‘’‘子类不继承父类’’’
class Frute(object):
def init(self,name):
self.name=name
def info(self):
print(“u’水果的名字是:{0}”.format(self.name))
class Apple(Frute):
def init(self,brand,color):
self.brand=brand
self.color=color
def info(self):
print(“品牌是{0},颜色是{1}”.format(self.brand,self.color))
f1=Apple(‘嘎啦’,‘绿色’)
f1.info()
来源:CSDN
作者:CSDNjunfangcui
链接:https://blog.csdn.net/CSDNjunfangcui/article/details/104158199