Advanced Python syntax - privatization - the privatization of understanding (4.3.1)

@

1. Description

__A (private): used only within the class object uses, but does not allow subclasses, other packages not be imported into
a (protected): may be used in a subclass can be accessed through the object, can not import other packages
A
: did not ask, is the difference between their definition of the name only

2. Code

test.py

a = 1
a_ = 1
__a = 1
_a = 1

main.py

from test import  *
import test
print(a)
print(a_)
print(test._a)
print(test.__a)
print(_a)
print(__a)
#输出前四个1

About the Author

Personal blog site
personal GitHub address
individual public number:
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/simon-idea/p/11402899.html