Private property name class name _ __ (forced access to the private property)

1  '' ' 
2  instance object can not directly access the private property, because the private genus python interpreter
 3  properties become _ __ class name attribute name, we can access the private property by property name __ _ class name.
4  
5  Caution: Do not do it! ! !
. 6  '' ' 
. 7  
. 8  class the Person ():
 . 9      DEF  the __init__ (Self, name):
 10          the self.name = name
 . 11          . Self __age = 0
 12 is  
13 is PER1 = the Person ( " Lily " )
 14  Print (per1.name)
 15  
16  Print (per1._Person__age)
 . 17  
18 is  # per1._Person__age = 200
19 # print(per1._Person__age)

 

Guess you like

Origin www.cnblogs.com/BKY88888888/p/11278742.html
Recommended