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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.