python-类与实例之间的联系

下面这段程序很清晰地呈现了类与实例之间的区别和联系。你能看明白吗?

class Example:

    t="come"
    __t1=3
    def __init__(self,name="example"):
        self.__name=name
    def getName(self):
        return self.__name
    def printt1(self):
        print(Example.__t1)
        self.__read()
        print(self.getName())
    def __read(self):
        print(Example.__t1)
p=Example()
print(p.getName())
print(Example.t)
p.printt1()

猜你喜欢

转载自blog.csdn.net/weixin_42039090/article/details/80552840
今日推荐