Python 判断列表中是否有元素被另一字符串包含

Python 判断列表中是否有元素被另一字符串包含

推荐阅读

all() 函数与 any() 函数

正文

python 复制代码
lst = ['das', 'it']
str1 = 'dasAuto'

if any(text in str1 for text in lst):
    print('The string contains at least one element from the list')
else:
    print('The string does NOT contain any of the elements in the list')
"""
result:
The string contains at least one element from the list
"""

如果大家觉得有用,就请点个赞吧~

相关推荐
白云千载尽31 分钟前
LQR与MPC.入门知识与实验
python·控制·mpc·lqr
weixin_4331793333 分钟前
Hangman 猜字游戏使用列表List实现
开发语言·python
52Hz1181 小时前
二叉树理论、力扣94.二叉树的中序遍历、104.二叉树的最大深度、226.反转二叉树、101.对称二叉树
python·算法·leetcode
卖个几把萌1 小时前
解决 Python 项目依赖冲突:使用 pip-tools 一键生成现代化的 requirements.txt
开发语言·python·pip
黎雁·泠崖1 小时前
Java字符串入门:API入门+String类核心
java·开发语言·python
哈哈不让取名字2 小时前
用Pygame开发你的第一个小游戏
jvm·数据库·python
程序员敲代码吗2 小时前
Python异步编程入门:Asyncio库的使用
jvm·数据库·python
sunfove2 小时前
Python小游戏:在 2048 游戏中实现基于线性插值(Lerp)的平滑动画
开发语言·python·游戏
2501_944526422 小时前
Flutter for OpenHarmony 万能游戏库App实战 - 抽牌游戏实现
android·开发语言·python·flutter·游戏
副露のmagic2 小时前
python基础复健
python·算法