首页 > 编程语言 > 详细

python -- 类中self到底有什么用?再续

时间:2020-05-03 22:14:13      阅读:58      评论:0      收藏:0      [点我收藏+]
a = 1


def 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到底有什么用?再续

原文:https://www.cnblogs.com/vincent-sh/p/12823586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!