i’m trying to find the docs for the function
in
Inside python. It is very hard because the search engine can’t function with a word like in.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“
in” is not a function. Its a built-in keyword. Using it can trigger the target objects__contains__()http://docs.python.org/reference/datamodel.html#object.contains
I say “can trigger” because the logic has different ways it might resolve under the hood:
Note that this example only covers a membership test, as opposed to using it to loop over an iterable.
To illustrate how
inis resolved during a loop operation, an iterator is first looked for using__iter__():In the event that the object does not have an
__iter__()defined, it will try using the older__getitem__(). Take a string, for instance, which does not have an__iter__(). This is just an illustration…And to show a similar iterator (generator here):