Skip to main content
 首页 » 编程设计

python之将 self.var(实例属性)作为默认方法参数传递

2024年10月17日7Renyi-Fan

<分区>

在函数 fiz 中分配 num1 = self.var1 时,Python 提示未解析的引用。这是为什么?

class Foo: 
 
    def __init__(self): 
        self.var1 = "xyz" 
 
    def fiz(self, num1=self.var1): 
        return