Ran*_*anH 0 python comparison tuples pacman
我有以下代码:
while current is not problem.getStartState():
print "Current: ", current, "Start: ", problem.getStartState()
Run Code Online (Sandbox Code Playgroud)
由于某种原因,比较效果不佳,您可以在以下输出中看到:
Current: (3, 5, 0, 0, 0, 0) Start: (4, 5, 0, 0, 0, 0)
Current: (4, 5, 0, 0, 0, 0) Start: (4, 5, 0, 0, 0, 0)
Run Code Online (Sandbox Code Playgroud)
你可以看到,即使current与getStartState()相同,它也会进入while.此外 - 当它曾经是一个2字段元组(x,y)时它工作正常.
我究竟做错了什么 ?谢谢
is测试身份,而不是平等.你要current != problem.getStartState()
有一个成语is (not) None,因为None保证是一个单身人士.除非你的意思是真的,否则不要将它用于其他类型!