use*_*794 1 python class function self
如何self.value在函数定义中调用 a ?
class toto :
def __init__(self):
self.titi = "titi"
def printiti(self,titi=self.titi):
print(titi)
Run Code Online (Sandbox Code Playgroud)
这是如何完成的:
def printiti(self, titi=None):
if titi is None:
titi = self.titi
print titi
Run Code Online (Sandbox Code Playgroud)
这是一个常见的 Python 习惯用法(将参数的默认值设置为 None 并在方法体中检查它)。