[Python learning journey] --- polymorphism (knowledge of class, object-oriented three characteristics: inheritance - polymorphism - Package)

the Name class: 
__A = 'You are a pig' # package variable A
DEF __init __ (Self, name):
self.name name =

DEF get_name (Self):
Print ( 'My name S%'% self.name)


N1 = the Name ( 'Chen Yuxia')
Print (the Name .__ dict__) # View class attributes dictionary
print (n1._Name__a) # can call __a in this manner, there is no real package


# the results:

{'__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}

You are a pig

Guess you like

Origin www.cnblogs.com/chenyuxia/p/12130446.html