小编Eth*_*han的帖子

为什么列表理解中的if-else之前,而if则在之后?

有关python可迭代理解的一般问题:

为什么这样的陈述

[s for s in x if s>2]
Run Code Online (Sandbox Code Playgroud)

if之后的去for,但像声明

[s if s>2 else None for s in x]
Run Code Online (Sandbox Code Playgroud)

if... else之前的云for

python list-comprehension

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

标签 统计

list-comprehension ×1

python ×1