Python string in list - Python是否有字符串'包含'子串方法?

Python string contains regex / python / string / substring / contains

我正在寻找Python中的 string.containsstring.indexof 方法。

我想做。

if not somestring.contains("blah"):
   continue

Peter Mortensen



Answer #1
"foo" in "foobar"
True

"foo" in "Foobar"
False

"foo" in "Foobar".lower()
True

"foo".capitalize() in "Foobar"
True

"foo" in ["bar", "foo", "foobar"]
True

"foo" in ["fo", "o", "foobar"]
False

["foo" in a for a in ["fo", "o", "foobar"]]
[False, False, True]