-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_08.py
More file actions
99 lines (68 loc) · 1.9 KB
/
demo_08.py
File metadata and controls
99 lines (68 loc) · 1.9 KB
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# create by oldman
# Date: 2019/01/11
# 面向对象
# 继承
class Cat:
def __init__(self, name, color="白色"):
self.name = name
self.color = color
def run(self):
print("{}在奔跑".format(self.name))
class Bosi(Cat):
def set_new_name(self, new_name):
self.name = new_name
def eat(self):
print("{}在吃东西".format(self.name))
def run(self):
print("我是Bosi的run方法")
# bs = Bosi("印度猫")
# # 虽然子类没有定义__init__方法,但是父类有,所以子类在继承父类的时候这个方法就被继承了,所以
# # 只要创建Bosi的对象,就会默认调用继承的那个__init__方法
# print(bs.name)
# print(bs.color)
# bs.eat()
# bs.set_new_name("波斯猫")
# bs.run()
# 多继承
# python中是可以多继承的
# 父类中的方法,属性,子类都会继承
class A:
def print_a(self):
print("-----A-----")
def do(self):
print("----A do-----")
class B:
def print_b(self):
print("----B-----")
def do(self):
print("----B do-----")
class C(A, B):
def print_c(self):
print("-----C-------")
# objc_c = C()
# objc_c.print_a()
# objc_c.print_b()
# objc_c.print_c()
# print(C.__mro__) # C类对象搜索方法时的先后顺序
# objc_c.do()
# 在子类中重写父类的方法
# 就是在子类中有一个和父类名字一样的方法,在子类中的方法会覆盖掉父类中同名的方法
class Dog():
def say(self):
print("dog.say")
class HbDog(Dog):
def say(self):
print("habog.say")
def say_father(self):
super().say()
# def say(self, aaa):
# print(aaa)
doga = HbDog()
doga.say()
doga.say("aaa")
doga.say_father()
# master 分支一般是线上的
# test 分支是在测试环境上的
# dev 分支是你在开发的时间用的