【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}
你是猪
相关推荐
class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =
lhxxhl 2020-05-16
bcbeer 2020-05-02
fly00love 2020-03-08
ladysosoli 2020-03-01
wangqing 2020-02-13
zhouhaihua00 2020-01-01
JakobHu 2019-12-21
pangrui0 2019-04-12
zhuquan0 2020-05-25
PHP学习笔记 2020-05-07
DCXabc 2020-05-01
liusarazhang 2020-03-06
zhuxianfeng 2020-03-03
Kwong 2020-03-01
liugan 2020-02-25