gpt4 book ai didi

python - 在一系列条件中获取列表内的值

转载 作者:行者123 更新时间:2023-11-30 23:13:02 25 4
gpt4 key购买 nike

假设您有以下代码:

if "walk" in myList or "run" in myList or "fly" in myList:
print("You "+dosomething()+" to the chamber on the left")

假设只有一个条件返回 true,如何找出条件中返回 true 的值,然后打印该值?

最佳答案

我会这样做:

for action in ('walk', 'run', 'fly'):
if action in myList:
print("You {} to the chamber on the left.".format(action))
break

一旦找到其中一个操作,break 将停止 for 循环,因此将显示第一个操作。

关于python - 在一系列条件中获取列表内的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29561078/

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