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
"""

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

相关推荐
做怪小疯子4 小时前
华为笔试0429
python·numpy
Warson_L4 小时前
Dictionary
python
寒山李白6 小时前
解决 python-docx 生成的 Word 文档打开时弹出“无法读取内容“警告
python·word·wps·文档·docx·qoder
2401_832365527 小时前
JavaScript中rest参数(...args)取代arguments的优势
jvm·数据库·python
Sirius.z7 小时前
第J3周:DenseNet121算法详解
python
2301_779622417 小时前
Go语言怎么用信号量控制并发_Go语言semaphore信号量教程【入门】
jvm·数据库·python
2301_766283447 小时前
c++如何将控制台输出保存到文件_cout重定向到txt【详解】
jvm·数据库·python
小康小小涵9 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
lzjava20249 小时前
Python的函数
开发语言·python
Awesome Baron9 小时前
skill、tool calling、MCP区别
开发语言·人工智能·python