python - 如何编写一个或条件来以 Python 方式检查子字符串?
问题描述
我想找到一种更优雅的编码方式:
str_example = "u are my // path"
if '//' in str_example or '/' in str_example:
do something
解决方案
用途all()
和any()
功能
str_example = "u are my // path"
if any(s in str_example for s in ['//', '/']):
pass
推荐阅读
- java - 如何使用 JUnit 测试读写锁?
- video-processing - 我正在使用 scc cfg 文件运行 HECV-SCM 编码器,但它无法输出 IDR 帧
- python - Flask:获取 AttributeError:'_AppCtxGlobals' 对象没有属性
- html - 尽管 CSS 中存在“pointer-event:none”,但绝对定位的叠加层会通过悬停事件
- swift - Firebase 查询语句 whereField(notIn) 不起作用
- html - flexbox中的水平滚动溢出父级
- android-studio - 如何在连续模式下配置 ktlint gradle 插件?
- typescript - 加载前更改模块内的 VUE 组件
- lisp - 从文件中剪辑阅读列表并将其展平,但不工作,不将 lst 识别为列表
- php - Symfony/Doctrine:获取可用命令列表