Using Python: Part 3: Tuples, Sets, and Dictionaries

Learning Python

Using Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.


Beyond Lists, there are also three other complex data types available in Python.

Tuples

Compared to Lists, Tuples are fixed sets of data. They are unchangeable once created.

In Python, tuples are defined through using round brackets around a comma-separated set of data.

Sets

In Python, a Set is an unordered collection of data. Unlike Lists, items within a Set cannot be accessed through their position. However, unlike Tuples, Sets can be changed. Items can be added, changed, and removed.

Sets are defined using curly brackets around a comma-separated set of data.

Dictionaries

Dictionaries can be thought of a special kind of Set. Unlike a series of data, entries are stored as key-value pairs. For whatever the key is, the value is returned.

Dictionaries are defined in Python through using curly brackets are comma-separated values. Each pair has a colon between the key, usually a string, and the value followed by a comma. The last entry does not have a comma.

Play with the example on Repl.it!