我用python编写了以下代码:
class state:
def _init_(self):
self.x=list([])
self.possibleChests=list([])
self.visitedChests=list([])
def checkKeys(self):
print self.x
def addKey(self,x):
self.x.append(key)
current_state=state()
future_state=state()
current_state.addKey(4)
当我运行它时,会出现以下错误:
AttributeError: state instance has no attribute 'x'
为什么没有将“x”识别为实例属性?你知道吗
在
__init__
周围需要双下划线:否则,Python将把函数当作普通方法,而不是^{} special method 。你知道吗
相关问题 更多 >
编程相关推荐