I checked it because there were a few things
python
# -*- coding: utf-8 -*-
class Hoge(object):
def __init__(self):
self.__foo = 'foo'
self._bar = 'bar'
hoge = Hoge()
# AttributeError: 'Hoge' object has no attribute '__foo'
# print hoge.__foo
print hoge._bar
print hoge._Hoge__foo
print hoge.__dict__
Execution result
bar foo {'_Hoge__foo': 'foo', '_bar': 'bar'}
Somehow Hoge .__ foo is a private property. The property with two unscos will behave like a private because name mandaring is performed.
It seems that hiding variables is not the main purpose, so I'll put it in my head for the time being.
Keep in mind that the rules of difficulty are primarily to prevent accidents; it is still possible to access and modify variables that are considered private in a convincing way. is. This specification is even useful in special situations such as debuggers.
http://docs.python.jp/2/tutorial/classes.html#tut-private