Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Equality by Reference and Value in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Below is a summary of equality by reference and value in different programming languages.

Loading...

Tips and Tricks

[] and [] are 2 indepedent (empty) list objects with different address. However, () and () are the same (empty) tuple singleton. The reason is that list is mutable while tuple is immutable.

False
True
True
True

Below are more examples.

False
False
True
True
False

Notice that since str is immutable (similar to tuple) in Python, it has similar behavior on equaility to tuple.

True
True
True