小编cha*_*ore的帖子

为什么Python没有"continue if"语句?

我认为这是一个非常易读的代码块,

for i in range(100):
    continue if i % 2 == 0
Run Code Online (Sandbox Code Playgroud)

但它在语法上并不正确.我们可以在Python中做其他好事,比如

for i in things:
    total += 3 if i % 2 == 0 else 1
Run Code Online (Sandbox Code Playgroud)

或者可能,

return a if b > a else c
Run Code Online (Sandbox Code Playgroud)

为什么我们不能continue if发表声明?

python python-3.x

6
推荐指数
1
解决办法
2314
查看次数

标签 统计

python ×1

python-3.x ×1