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 anthony-flury
Recipients anthony-flury, docs@python
Date 2021-02-25.23:11:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614294680.42.0.115546489096.issue43325@roundup.psfhosted.org>
In-reply-to
Content
A frequent bug for beginners is to assume that 'is' is somehow 'better' then '==' when comparing values, and it is certainly a cause for confusion amongst beginners as to why:

   [1,2] is [1,2] evaluates to False but
   'a' is 'a' evaluates to True

    and many similar examples.

As far as I can see the first mention of the 'is' operator is under Section 5 - More on conditionals : https://docs.python.org/3/tutorial/datastructures.html?highlight=comparison#comparing-sequences-and-other-types; and it is mentioned thus : 

  The operators is and is not compare whether two objects are really
  the same object; this only matters for mutable objects like lists.

As we know though this statement is misleading - it suggests that 'is' can be used to compare immutable values (ints, strings, tuples) etc, and while for some values of some immutables (small ints, shortish strings) 'is' can be used as an equivalent of '==' it wont be clear from this 'statement' that 'is' is simply not a safe way to compare values.

There needs to be a warning here about 'is' and how it is not an equivalent to '==' in any general sense.
History
Date User Action Args
2021-02-25 23:11:20anthony-flurysetrecipients: + anthony-flury, docs@python
2021-02-25 23:11:20anthony-flurysetmessageid: <1614294680.42.0.115546489096.issue43325@roundup.psfhosted.org>
2021-02-25 23:11:20anthony-flurylinkissue43325 messages
2021-02-25 23:11:20anthony-flurycreate