相关疑难解决方法(0)

没有其他的Python三元运算符

是否可以在Python中的一行中执行此操作?

if <condition>:
    myList.append('myString')
Run Code Online (Sandbox Code Playgroud)

我试过三元运算符:

myList.append('myString' if <condition>)
Run Code Online (Sandbox Code Playgroud)

但我的IDE(MyEclipse)不喜欢它,没有else.

python ternary

62
推荐指数
5
解决办法
5万
查看次数

标签 统计

python ×1

ternary ×1