Linux/Unix > Python Essential Reference, Second Edition > 4. Operators and Expressions > Object Equality and Identity | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238110137104031089151165159136080

### Object Equality and Identity

The equality operator `x` `==` `y` tests the values of `x` and `y` for equality. In the case of lists and tuples, all the elements are compared and evaluated as true if they’re of equal value. For dictionaries, a true value is returned only if `x` and `y` have the same set of keys and all the objects with the same key have equal values.

The identity operators `x` `is` `y` and `x` `is not` `y` test two objects to see whether they refer to the same object in memory. In general, it may be the case that `x` `==` `y` , but `x` `is not` `y` .

Comparison between objects of non-compatible types such as a file and a floating-point number may be allowed, but the outcome is arbitrary and may not make any sense. In addition, comparison between incompatible types may result in an exception.

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.