Python中默认的成员函数,成员变量都是公开的(public),而且python中没有类似public,private等关键词来修饰成员函数,成员变量。
在python中定义私有变量只需要在变量名或函数名前加上 ”__“两个下划线,那么这个函数或变量就会为私有的了。
运行结果:
test_1 is ok....
Traceback (most recent call last):
File "D:\Install\Eclipse\WorkSpace\Python\test_class.py", line 15, in
test.__test_2()
AttributeError: Test instance has no attribute '__test_2'