gpt4 book ai didi

python - 是否可以从 python 的范围中排除一些数字?

转载 作者:行者123 更新时间:2023-11-28 21:39:41 25 4
gpt4 key购买 nike

示例:那段代码是否正确(如果不正确,正确的解决方案是什么?):

for x in range(13,19)\{15,16}

最佳答案

您可以使用以下条件生成器表达式:

for x in (n for n in range(13, 19) if n not in {15, 16}):
# do stuff with x

关于python - 是否可以从 python 的范围中排除一些数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46425324/

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