My Tech Notes
Python: string comparison == or is
Use
==
when comparing values and
is
when comparing identities.
>>> a = 'abc' >>> b = ''.join(['a', 'b', 'c']) >>> a == b True >>> a is b False
see also
Why does comparing strings in Python using either '==' or 'is' sometimes produce a different result?
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment