所以伙计们。如果我有
example = "1", "2", "3"
我将如何检查是否有任何项目在字符串中。
使用any()
:
if any(s in some_string for s in example):
# at least one of the elements is a substring of some_string
一个例子:
>>> example = "1", 2, "3"
>>> str in [type(entry) for entry in example]
如果元组中有 str,将返回 True。