"not in"运算符在 Python 中起什么作用?

pythonserver side programmingprogramming更新于 2025/8/6 8:44:17

在 Python 中,in 和 not in 运算符称为成员运算符。它们的目的是检查对象是否是某个序列对象(如字符串、列表或元组)的成员。如果对象存在于序列中,not in 运算符返回 false,如果未找到,则返回 true

>>> 'p' not in 'Tutorialspoint'
False
>>> 'c' not in 'Tutorialspoint'
True
>>> 10 not in range(0,5)

相关文章


有用资源