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.

Data Structures in Python

Python data structures

Up to this point, we’ve been working with what are called “primitive” data types in Python. These include integer, float, string, and Boolean.

But we can imagine scenarios where we want to be able to work with more complex data structures or more complex ways of storing and accessing information in a programming language.

In this chapter, we’re going to focus on some of the one-dimensional (or linear) data structures available to us in Python. These include strings, lists, tuples, sets, and dictionaries.

NameSyntaxExampleDescription
Stringstr(), """Hello world!"Sequence of characters
Listlist(), []["apple", "banana", "pear"], [1, 3, 5, 7]Sequence of objects/values
Dictionarydict(), {}{'first_name': 'Knute', 'last_name':'Rockne', 'class':'1918'}Key-value pairs
Setset(), {}{"apple", "banana", "pear"}, {1, 3, 5, 7}Unordered group of unique values
Tupletuple(), ()("apple", "banana", "pear"), (1, 3, 5, 7)Ordered group of values that can include duplicates

We can use a few key questions or attributes to distinguish or compare these data structures:

This chapter provides an overview of foundational programming concepts in the areas of data structures and data storage, with a focus on Python syntax.

Topics covered include:

Acknowledgements

Elements of this chapter were adapted from materials developed by:

Application

Your answers to this chapter’s application questions should be added to the notebook template.

Submit the Colab link on Canvas for the assignment submission.