My Tech Notes
Search This Blog
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
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment