gpt4 book ai didi

python - 如何在 Python 中使用字符串搜索关键字

转载 作者:行者123 更新时间:2023-11-28 16:56:45 25 4
gpt4 key购买 nike

您好,我需要一些帮助来创建字符串,这些字符串将抓取包含提及 Yeezy + Footpatrol 的推文。

因此,如果提到 Footpatrol,它只会选择 Yeezy。

我不想专门写可变字符串例如:

t = ['Hello world!',
'Hello World!',
'Hello World!!!',
'Hello world!!!',
'Hello, world!',
'Hello, World!']

我只想在同一行文本中同时提到 footpatrol 和 Yeezy 时使用嵌套 for 循环推送转发。

最佳答案

使用 in 关键字:

if 'footpatrol' in line and 'Yeezy' in line:
# Do your stuff
# Pass

关于python - 如何在 Python 中使用字符串搜索关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57693137/

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