【Python学习之旅】---多态(类的相关知识,面向对象三大特性:继承-多态-封装)

class Name:    __a=‘你是猪‘ #封装变量a    def __init__(self,name):        self.name=name    def get_name(self):        print(‘我叫%s‘ %self.name)n1=Name(‘陈宇霞‘)print(Name.__dict__) #查看类属性字典print(n1._Name__a)   #可以通过此种方式调用__a ,没有真正的封装#执行结果:

{‘__module__‘: ‘__main__‘, ‘_Name__a‘: ‘你是猪‘, ‘__init__‘: <function Name.__init__ at 0x00000242BD968EA0>, ‘get_name‘: <function Name.get_name at 0x00000242BD968E18>, ‘__dict__‘: <attribute ‘__dict__‘ of ‘Name‘ objects>, ‘__weakref__‘: <attribute ‘__weakref__‘ of ‘Name‘ objects>, ‘__doc__‘: None}

你是猪

相关推荐