faqts : Computers : Programming : Languages : Python : Language and Syntax

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 16 people (94%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

What does == test for? In Java, there's both == and equals(). What are the Python equivalents?

Jun 29th, 2000 13:32
Jason Trowbridge, Robb Shecter, http://www.python.org/doc/current/ref/customization.html#l2h-130


Python's '==' seems to be similar to Java's 'equals()', since the first
object's __cmp__ method is called to evaluate equality.  Python's 'is'
operator seems to be similar Java's '==' operator, as 'is' tests the
object's identity.

If the first object in Python's '==' operator does not have a __cmp__
method defined, the '==' operator falls back to testing for object
identity.