相关疑难解决方法(0)

三元运算符的语法错误

我是Python的新手,我正在尝试使用具有这种格式的三元opertor(我想是这样)

value_true if <test> else value_false
Run Code Online (Sandbox Code Playgroud)

这是一段代码:

expanded = set()

while not someExpression:

    continue if currentState in expanded else expanded.push(currentState)

    # some code here
Run Code Online (Sandbox Code Playgroud)

但Python不喜欢它并说:

SyntaxError: invalid syntax (pointed to if)
Run Code Online (Sandbox Code Playgroud)

怎么解决?

python ternary-operator

2
推荐指数
1
解决办法
1722
查看次数

标签 统计

python ×1

ternary-operator ×1