Python检查元组中的任何项是否在字符串中

2024-04-24 03:02:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Check if multiple strings exist in another string
Check to ensure a string does not contain multiple values

伙计们。如果我有

example = "1", "2", "3"

我该如何检查是否有任何项在字符串中。


Tags: toinstringifcheckanothernotmultiple
2条回答

一个例子:

>>> example = "1", 2, "3"
>>> str in [type(entry) for entry in example]

如果元组中有str,则返回True。

使用^{}

if any(s in some_string for s in example):
    # at least one of the elements is a substring of some_string

相关问题 更多 >