我是Python的新手,正在尝试使用三元运算符,其格式应该是这样的(我觉得是这样的)
value_true if <test> else value_false
这是一段代码片段:
这是一段代码片段:
expanded = set()
while not someExpression:
continue if currentState in expanded else expanded.push(currentState)
# some code here
但是Python不喜欢它,会显示如下错误信息:
SyntaxError: invalid syntax (pointed to if)
如何解决这个问题?
not x in y
=x not in y
。 - user395760print
。 - Ashwini Chaudharycontinue
。只需将 "一些代码" 添加到if
块中,并将其添加到expanded
中(请参见我的代码的最后一行)。 - defuzone if condition else two
。对于语句:if condition: do_something()
。 - defuz