gpt4 book ai didi

Python 如果 x 在 y

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:35 24 4
gpt4 key购买 nike

if "test" in ['testtext', 'aaaa', 'texttext']:
print("yes")
else:
print("no")

这将始终输出“否”。我怎样才能改变它,使其输出"is",因为“test”一词出现在“testtext”中,即使它只是它的一部分?

最佳答案

您可以使用 any() 内置函数:

if any("test" in w for w in ['testtext', 'aaaa', 'texttext']):
print("yes")
else:
print("no")

打印:

yes

关于Python 如果 x 在 y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56916624/

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