• 【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}

    你是猪

  • 相关阅读:
    nyoj 16 矩形嵌套
    nyoj 44 子串和
    nyoj 448 寻找最大数
    nyoj 14 会场安排问题
    hdoj 1008 Elevator
    bzoj1588
    bzoj3224
    bzoj1503
    bzoj1834
    bzoj1066
  • 原文地址:https://www.cnblogs.com/chenyuxia/p/12130446.html
Copyright © 2020-2023  润新知