'11' + '1' is '111'?
ben+python at benfinney.id.au
Fri Oct 30 02:08:05 CET 2009
metal <metal29a at gmail.com> writes:
> '11' + '1' == '111' is well known.
> but it suprises me '11'+'1' IS '111'.
Don't be surprised. Rather, don't depend on implementation-dependent
behaviour, such as whether two objects that compare equal will or will
not have the same identity.
That behaviour is permitted to differ based on which Python
implementation, which specific value, or even which phase the moon is
Use ‘is’ when you want to compare identity. Use ‘==’ when you want to
compare equality. Use more thinking time when you don't yet know which
one you want.
\ “The fact that I have no remedy for all the sorrows of the |
`\ world is no reason for my accepting yours. It simply supports |
_o__) the strong probability that yours is a fake.” —Henry L. Mencken |
More information about the Python-list