python里面有没有类似string.contains或者string.indexof函数?
1AbbenMar 24, 2020直接用in操作符就行了if "something-you-care" in somestring: pass或者finds = "This be a string" if s.find("is") == -1: print("No 'is' here!") else: print("Found 'is' in the string.")或者operatorimport operator if not operator.contains(somestring, "blah"): continue或者countstring.count("bah") >> 0 string.count("Hello") >> 1或者re>>> import re >>> print(re.findall(r'( |t)', to_search_in)) # searches for t or space ['t', ' ', 't', ' ', ' ']and so on.
直接用in操作符就行了
或者find
或者operator
或者count
或者re
and so on.