python字符串notin
发布时间: 2025-08-14 13:46:58
A. Python中关系运算符in,not in在字符串表达式和列表的使用时有什么区别和注意点
Membership test operations
For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expressionxinyis equivalent toany(xiseorx==eforeiny).
For the string and bytes types,xinyisTrueif and only ifxis a substring ofy. An equivalent test isy.find(x)!=-1. Empty strings are always considered to be a substring of any other string, so""in"abc"will returnTrue.
翻译:
对容器类型,例如list、tuple、set、frozenset、dict或collections.deque,表达式x in y等价于any(x is e or x == e for e in y)。
对字符串和bytes类型,x in y为真当且仅当x是y的子串。等价测试为y.find(x) != -1。空字符串永远被视作是其他任何字符串的子集,因此"" in "abc"将返回True。
热点内容