我创建了class,当我不加下划线并调用name()函数时会出现错误'str' object is not callable.
想问一下变量加不加下划线有什么区别吗?
#这样会报错
class Test:
def __init__ (self, name):
self.name = name
def name(self):
return self.name
#这样有下划线正确输出
class Test:
def __init__ (self, name):
self._name = name
def name(self):
return self._name