Python Built-in Data Structures

Lauren Yu
1 min readJul 13, 2020
Photo by Joshua Sortino on Unsplash

So you’re interested in learning Python. One of the first things to learn about are the four built-in data structures. Check out the examples below for a quick overview!

  1. LISTS
    Example:
    l = [1, 2, “a”]
    Contents: ordered sequence of objects
    Mutable/Immutable: mutable — can add or remove elements
    Similar to: array
    Built with: enclosed with brackets
  2. TUPLES
    Example:
    tup = (1, 2, “a”)
    Contents: ordered sequence of objects
    Mutable/Immutable: immutable — cannot add or remove elements
    Similar to: array
    Built with: enclosed with parentheses(optional)
    Note: Faster and consumes less memory that lists
  3. DICTIONARIES
    Example:
    dict = {“a”:1, “b”:2}
    Contents: unordered; have keys(unique) and values
    Mutable/Immutable: immutable — cannot add or remove elements
    Similar to: JS object or Ruby hash
    Built with: curly brackets
  4. SETS
    Example:
    countries = set([‘brazil’, ‘germany’, ‘india’])
    Contents: unordered, must be unique and immutable
    Mutable/Immutable: mutable (frozensets are sets that are immutable)
    Built with: set() built-in function
    Note: think Venn Diagram/set theory

--

--

Lauren Yu

Software engineer/full-stack developer and founding member of the Breaking Winds Bassoon Quartet.