homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Eric Lafontaine
Recipients Eric Lafontaine, christian.heimes, docs@python, ezio.melotti, mark.dickinson, nparikh, r.david.murray, vstinner
Date 2017年02月08日.01:25:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486517105.06.0.812064615771.issue16011@psf.upfronthosting.co.za>
In-reply-to
Content
Hi all,
Here are the test I've made to understand the behavior :
class Foo_42(object):
 def __contains__(self,item): return 42 
 
class Foo_neg(object):
 def __contains__(self,item): return -42 
 
class Foo_None(object):
 def __contains__(self,item): return 
 
class Foo_false(object):
 def __contains__(self,item): return False 
 
class Foo_true(object):
 def __contains__(self,item): return True
for foo in [Foo_false(),Foo_None(),Foo_neg(),Foo_true(),Foo_42()]:
 print("3 in foo:" + str(3 in foo))
 print("foo.__contains__(3)" + str(foo.__contains__(3)))
 
which output this :
3 in foo:False
foo.__contains__(3)False
3 in foo:False
foo.__contains__(3)None
3 in foo:True
foo.__contains__(3)-42
3 in foo:True
foo.__contains__(3)True
3 in foo:True
foo.__contains__(3)42
So as long as __contains__ return False or None, the 'in' operator will be False. Otherwise true.
History
Date User Action Args
2017年02月08日 01:25:06Eric Lafontainesetrecipients: + Eric Lafontaine, mark.dickinson, vstinner, christian.heimes, ezio.melotti, r.david.murray, docs@python, nparikh
2017年02月08日 01:25:05Eric Lafontainesetmessageid: <1486517105.06.0.812064615771.issue16011@psf.upfronthosting.co.za>
2017年02月08日 01:25:04Eric Lafontainelinkissue16011 messages
2017年02月08日 01:25:03Eric Lafontainecreate

AltStyle によって変換されたページ (->オリジナル) /