有没有办法在类中保留一个私有(private)类变量并仍然将其用作非默认变量的默认值(无需在类外定义该值)?
例子:
class a:
def __init__(self):
self.__variable = 6
def b(self, value = self.__variable):
print value
最佳答案
你想多了:
class a:
def __init__(self):
self.__variable = 6
def b(self, value=None):
if value is None:
value = self.__variable
print value
关于python - 在 python 中使用类变量作为非默认参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4638008/