成员修饰符
私有成员
__字段名
class Foo:
def __init__(self, name, age):
self.__name = age#私有,外部无法直接访问
def show(self):
return sef.__age
obj = Foo('age',23)
ret = obj.show()
print(ret)
class Foo:
__v = '123'
def __init__(self):
pass
def show(self):
return Foo.__v
@staticmethod
def start(self):
return Foo.__v
print(Foo.__v)
ret = Foo().show()
print(ret)
ret = Foo.start()
print(ret)
##
class Foo:
def __f1(self):
return 123
def f2(self):
r = self.__f1()
return r
obj = Foo()
obj.f1()
ret = obj.f2()
###
类的特殊成员
异常处理
反射
单例模式