__contains__()

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Feb 15 22:24:14 EST 2001


John Schmitt wrote:
> 
> The manual doesn't say that it must strictly
> return 0 or 1, just something true or false.

Which is what you're doing, and it's interpreting it as
"true". It also doesn't say that "x in y" will return
the exact value returned by y's __contains()__ method,
either.

The reason is that, internally, it's being funneled
through the C version of the __contains__ method in
the typeobject, which returns a C int, not a general
Python object. The interpreter then converts that into
a canonical Python boolean value.

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list