1.contains 方法用途

        contains 方法可以判断子串是否在原字符串中。

2.contains 来源

        contains 方法在 operator 模块中,operator模块是 Python 中内置的操作符接口,它定义了一些算数、比较、逻辑、序列运算的函数,operator 模块是用 C语言 实现的,所以执行速度比 Python 代码快。

3.contains 用法举例

# 导入operator模块
import operator
#调用 operator 中的 contains 方法,判断子串是否在原字符串中。是,则返回True 否,返回 False
print(operator.contains('Hello world!','wor')) 
print(operator.contains('Hello world!','woc'))

输出:

True
False

更多推荐

Python——contains方法