Link Search Menu Expand Document

Dictionaries

Table of contents

  1. Description
  2. Example
  3. Keys
  4. Mutability
  5. Instructional Video

Description

A dictionary is a collection of key-value pairs enclosed by curly braces ({}). A colon (:) separates each key from its value.

  • Mutable: you can change any of their attributes.
  • Keys, like index numbers, allow access to individual values. Keys must be unique and immutable.
  • Ordered: key/value pairs are stored in a dictionary in a specific order.
  • Many different actions (methods and functions) can be performed on dictionaries.
  • Python Docs: Dictionaries, Mapping Types

Example

Run in Repl.it

Keys

  • Keys must be an immutable data types. Dictionaries, lists, and sets cannot be dictionary keys because they are mutable.
  • Keys must be unique. One dictionary cannot have two different keys by the same name.

Mutability

Dictionaries are mutable, which means their attributes can be changed after instantiation.

Instructional Video