Sample
>>>
class Student (object):
__name = 0
_sex = ' Male '
>>> student.__dict__
Mappingproxy ({' __module__ ': ' __main__ ', ' _student__name ': 0, ' _sex ': ' Male ', ' __dict__ ': <attribute ' __dict__ ' Student ' objects>, ' __weakref__ ': <attribute ' __weakref__ ' of ' student ' objects>, ' __doc__ ': None})
> >> student.__name
Traceback (most recent call last):
File "<pyshell#58>", line 1, in <module>< C9/>student.__name
attributeerror:type object ' student ' has no attribute ' __name '
>>> student._ Student__name
>>> student._sex
' Male '
look carefully and carefully you will find the problem
summary: we declared a student class that defined a member with an underscore and a double underline, and then we tried to access the members, and we found that the members of the double underscore could not be accessed directly through the __dict__ we see inside the class, Python automatically interprets __name as _student__name, so we use _student__name to access this success. However, _name is unaffected. So: Two underline: Python class built-in members dedicated to distinguish user-defined members of the single underline: Class of ordinary Members of the underline: the parser automatically converted to: _ Class name __ member name, in lieu of the original member, Access needs to be in the original member name before adding _ class name.