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

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

相关推荐
风早爽太5 小时前
用 ‌Render‌ 快速部署网站和常见问题解决
python·fastapi
李航19836 小时前
给自己的图形引擎,配上了AI渲染,做设计真是太方便了
人工智能·python·计算机视觉·ai·ai编程
L@ncor6 小时前
第六章 框架开发实践 · 学习笔记(AutoGen / AgentScope / CAMEL / LangGraph)
python·框架·autogen·langgraph·agentscope
Zhou1411367 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
摇滚侠8 小时前
《On Java 中文版 基础卷》阅读笔记 对象无处不在 03
java·笔记·python
小小小小钰儿8 小时前
1.5-Python网络编程
开发语言·网络·python·web安全·计算机·网络安全
keke.shengfengpolang8 小时前
2026年金融风控岗技术能力拆解:SQL取数、Python建模、评分卡项目,校招面试到底考什
python
kyrie_sakura9 小时前
大模型学习7 -- 深度学习2 -- 张量
python·深度学习
智鸟科技GemeOpen开发者智能设备10 小时前
智能插座二次开发如何接入Home Assistant,从零开始完整工程实现(Python+React)
开发语言·python·物联网·react.js·智能家居