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

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

相关推荐
Nuanyt几秒前
Agent 学习笔记(下篇二):Claude Code 生态、RAG 与 Memory(Stage 5–6)
笔记·python·memory·rag·aiagent·claude code·agentskill
用户298698530142 分钟前
Python 实战:Markdown 转 PDF 的代码实现与页面设置
python·api·markdown
thusloop3 分钟前
零门槛接入 GPT-6-astra 与 claude-opus-5-5,三大场景实战指南
python·gpt·算法·agent·claude·codex
程序猿乐锅14 分钟前
Streamlit 实现 AI 聊天 Agent:角色提示词、流式输出与会话管理
开发语言·前端·笔记·后端·python·学习
小南知更鸟18 分钟前
【2026 年 Python 包管理工具选型:从“工具崇拜”回到工程约束】
开发语言·python
TomEval24 分钟前
【测AI】第20篇:大模型安全测试 —— 越狱攻击与防护
人工智能·python·功能测试·ai·aigc·测试用例·安全性测试
RuoyiOffice34 分钟前
达梦 DM8 + openGauss:RuoYi Office 的 MySQL 数据转换与导入实践
数据库·spring boot·python·sql·信创
用户03321266636735 分钟前
轻松使用 Python 将 RTF 转换为 Word 文档(含批量转换与格式互转)
python
程序猿乐锅1 小时前
面向对象练习:图书借阅系统里的封装、抽象类与多态
开发语言·前端·数据库·后端·python·学习·1024程序员节
xyouyuweizhu1 小时前
Java IO 流详解:流的作用、流的划分与标准输入输出流
java·python·php