【发布时间】:2012-09-20 15:54:43
【问题描述】:
可能重复:
Check if multiple strings exist in another string
Check to ensure a string does not contain multiple values
所以伙计们。如果我有
example = "1", "2", "3"
如何检查是否有任何项目在字符串中。
【问题讨论】:
可能重复:
Check if multiple strings exist in another string
Check to ensure a string does not contain multiple values
所以伙计们。如果我有
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 元组中的每个字符串。
一个例子:
>>> example = "1", 2, "3"
>>> str in [type(entry) for entry in example]
如果元组中有 str,则返回 True。
【讨论】: