The in
keyword can be used in different ways, but in this case, it's used to check if something contains something else. According to a documentation page about this, the in
keyword calls __contains__
, i.e.: x in y
is the same as y.__contains__(x)
.
If SomeType.__contains__
is not defined by SomeType
...
...the membership test first tries iteration via __iter__()
, then the old sequence iteration protocol via __getitem__()
.
This would most likely be in linear time (O(n)
). I say "most likely" because it depends on those implementations.
The in-built list
type can have elements of different types and is not typically sorted, making binary search impossible (or at least illogical) and therefore, as stated by Green Cloak Guy, the CPython implementation performs the check linearly.
To answer the question in one term, it would be: "Linear Search."