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

标签 python tweepy

您好,我需要一些帮助来创建字符串,这些字符串将抓取包含提及 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/

相关文章:

Python 子进程 FileNotFoundError

python - web2py 中的 "unable to import requests"即使请求可以直接通过 python 访问

python - tweepy/twitter api 错误类型

python - 是否有用于从文本中查找和提取字符串的正则表达式

python - 根据序列位置在列表之间创建组合

python - 如何解决将推文数据插入 Apache Cassandra 数据库时遇到的错误?

python - 在 python 中使用 Tweepy 及其跟随给定用户但不退出循环

Python Tweepy 编码(utf-8)

python - Tweepy,UnicodeEncodeError USC-2

python - 有没有一种更优雅/优化的方式来实现这种连接算法?