Pragmatics of the is operator

Chris Angelico rosuav at gmail.com
Sat Nov 26 20:50:52 EST 2011


On Sun, Nov 27, 2011 at 12:42 PM, candide <candide at free.invalid> wrote:
> So, for the same reason, wouldn't it be better to use "if spam is True"
> against to "if spam == True"  (or better "if spam") ?
>

They're quite different. "if spam" will check the truthiness of spam -
it's equivalent to "if bool(spam) is True"; "if spam is True" checks
that it's actually a boolean. But I would recommend against the "==
True" form, as it's unclear which form you meant to use. (Others may
disagree.)

ChrisA



More information about the Python-list mailing list