这工作:Python语法错误不是()操作
>>> not(True)
False
>>> a = {}
>>> a["hidden"] = False
>>> a["hidden"] = not(a["hidden"])
>>> a["hidden"]
True
但不是这样的:
def toggleHelp(self, event):
# https://stackoverflow.com/questions/10267465/showing-and-hiding-widgets#10268076
if (self.special_frame["hidden"] == False):
self.special_frame.grid_remove()
else:
self.special_frame.grid()
self.special_frame["hidden"] == not(self.special_frame["hidden"])
错误
line 563
self.special_frame["hidden"] == not(self.special_frame["hidden"])
^
SyntaxError: invalid syntax
在init:
self.special_frame["hidden"] = False
我做错了什么?
'not'被用作一个操作符,而不是作为一个功能。坏:“不(真)”;好:不是真的。 –
问题是''==操作符。将其更改为'=',语法错误将消失。此外,您通常不希望使用'不(X)',只是用'不x'除非你真的需要括号出于某种原因。 –