Monday, April 2, 2012

Python: [] vs. {} vs. ()

Reference: http://stackoverflow.com/q/4407873/1276534
Authors: Zolomon, Greg Hewgill, Andrew Jaffe

It is a good note post to make sure we remember what is [] vs. {} vs. ()

() - tuple

A tuple is a sequence of items that can't be changed (immutable).

[] - list

A list is a sequence of items that can be changed (mutable).

{} - dictionary or set

A dictionary is a list of key-value pairs, with unique keys (mutable). From Python 2.7/3.1, {} can also represent a set of unique values (mutable).

No comments:

Post a Comment