Python:类中的私有方法
类中的私有方法
在Python中使用_或 __开头的方法名称,表示方法对类是“私有的”,而不是由外部程序使用的。
例如
class Test:
def __init__(self):
pass
def __privateMethod(self):
pass
moyutime:本文仅是学习心得,观点仅供参考,祝愿读者学习途中快乐且不断有所收获。
在Python中使用_或 __开头的方法名称,表示方法对类是“私有的”,而不是由外部程序使用的。
例如
class Test:
def __init__(self):
pass
def __privateMethod(self):
pass