Commit d0cda1dc authored by Raymond Hettinger's avatar Raymond Hettinger

SF patch #760792: "wo" in "word" now valid but not documented as such

Revised version of a contribution from Gerrit Holl.

Update the docs for the extended behavior of __contains__
parent f6fe4eda
...@@ -913,10 +913,13 @@ only if there exists an index \var{i} such that ...@@ -913,10 +913,13 @@ only if there exists an index \var{i} such that
\code{\var{x} == \var{y}[\var{i}]} is true. \code{\var{x} == \var{y}[\var{i}]} is true.
For the Unicode and string types, \code{\var{x} in \var{y}} is true if For the Unicode and string types, \code{\var{x} in \var{y}} is true if
and only if there exists an index \var{i} such that \code{\var{x} == and only if \var{x} is a substring of \var{y}. An equivalent test is
\var{y}[\var{i}]} is true. If \code{\var{x}} is not a string or \code{y.find(x) != -1}. Note, \var{x} and \var{y} need not be the
Unicode object of length \code{1}, a \exception{TypeError} exception same type; consequently, \code{u'ab' in 'abc'} will return \code{True}.
is raised. Empty strings are always considered to be a substring of any other string,
so \code{"" in "abc"} will return \code{True}.
\versionchanged[Previously, \var{x} was required to be a string of
length \code{1}]{2.3}
For user-defined classes which define the \method{__contains__()} method, For user-defined classes which define the \method{__contains__()} method,
\code{\var{x} in \var{y}} is true if and only if \code{\var{x} in \var{y}} is true if and only if
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment