首页 > 解决方案 > 如何编写一个或条件来以 Python 方式检查子字符串?

问题描述

我想找到一种更优雅的编码方式:

str_example = "u are my // path"
if '//' in str_example or '/' in str_example:
    do something

标签: python

解决方案


用途all()any()功能

str_example = "u are my // path"
if any(s in str_example for s in ['//', '/']):
    pass

https://docs.python.org/3/library/functions.html#all


推荐阅读