python -- 类中self到底有什么用?再续
a = 1def say():
print('调用了全局方法(people外)')
class Creative_1(object):
def say(self):
print('来自Creative_1的say')
class Creative(object):
c=100
def say(self):
print('来自Creative的say')
def creative_say(self):
self.say()
class People(Creative_1,Creative):
a = 100
b = 123
def __init__(self):
self.a = 10000
@classmethod
def talk(cls):
print('这里是people类方法')
def say(self):
print('调用了People类里面的方法')
# def say():
# print('来自无需self的say函数')
@staticmethod
def tool():
print('来自People类的工具包')
def do(self):
say()
super().say()
self.say()
Creative.say(self)
print('a = ', a)
print('self.a = ', self.a)
print('self.b = ', self.b)
print('self.c = ', self.c)
print('People.b = ', People.b)
p = People()
p.do()
p.creative_say()
揭晓答案
调用了全局方法(people外)来自Creative_1的say
调用了People类里面的方法
来自Creative的say
a = 1
self.a = 10000
self.b = 123
self.c = 100
People.b = 123
调用了People类里面的方法
View Code
以上是 python -- 类中self到底有什么用?再续 的全部内容, 来源链接: utcz.com/z/386761.html