gpt4 book ai didi

python - 为什么在列表理解中是 if-else before 而 just if 是 after?

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:02 25 4
gpt4 key购买 nike

<分区>

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

为什么是这样的声明

[s for s in x if s>2]

if 位于for 之后,但对于像

这样的语句
[s if s>2 else None for s in x]

if...elsefor 之前?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com