Open links in new tab
  1. A dictionary in Python is a built-in, mutable collection that stores data as key-value pairs, where each key is unique and maps to a specific value. Keys must be hashable (e.g., strings, numbers, tuples), while values can be of any type.

    Example: Creating and accessing a dictionary

    # Creating a dictionary
    person = {
    "name": "Alice",
    "age": 30,
    "skills": ["Python", "Data Analysis"]
    }

    # Accessing values
    print(person["name"]) # Alice
    print(person.get("age")) # 30

    # Adding/Updating values
    person["city"] = "New York"
    person["age"] = 31

    # Removing items
    del person["city"]
    removed_age = person.pop("age")

    print(person) # {'name': 'Alice', 'skills': ['Python', 'Data Analysis']}
    Copied!

    In this example, "name", "age", and "skills" are keys, while "Alice", 30, and the list are their values.

    Creating dictionaries

    • Using curly braces {}:

    d1 = {"a": 1, "b": 2}
    Copied!
    • Using dict() constructor:

    d2 = dict(x=10, y=20)
    Copied!
    • From iterable of tuples:

    pairs = [("name", "Bob"), ("age", 25)]
    d3 = dict(pairs)
    Copied!

    Common operations

    • Access values: my_dict[key] or my_dict.get(key, default)

    • Add/Update: my_dict[key] = value

    • Delete: del my_dict[key] or my_dict.pop(key)

    • Iterate:

  1. Python Dictionaries - W3Schools

    Dictionary items are ordered, changeable, and do not allow duplicates. Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
    Dictionary

    Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered*, changeable and do not allow duplicates. Dictionaries are written with curly brackets, and have keys and values:

    Ordered Or unordered?

    When we say that dictionaries are ordered, it means that the items have a defined order, and that order will not change. Unordered means that the items do not have a defined order, you cannot refer to an item by using an index.

    Changeable

    Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created.

    Python Collections

    There are four collection data types in the Python programming language: 1. Listis a collection which is ordered and changeable. Allows duplicate members. 2. Tupleis a collection which is ordered and unchangeable. Allows duplicate members…

  2. Dictionaries in Python – Real Python

    In this tutorial, you'll learn how to work with Python dictionaries to help you process data more efficiently. You'll learn how to create dictionaries, access their keys …

  3. Python Dictionary - GeeksforGeeks

    Mar 28, 2026 · Python dictionary is a data structure that stores information in key-value pairs. While keys must be unique and immutable (like strings or numbers), values can be of any data type, whether mutable or immutable.

  4. Python Dictionary - Python Tutorial

    In this tutorial, you'll learn about Python Dictionary which allows you to organize related information.

  5. Python Dictionary (Dict) Tutorial - AskPython

    Jan 20, 2026 · If you’ve been programming for more than five minutes, you’ve probably used a dictionary without realizing it. They’re everywhere because they …

  6. Python - Dictionaries - Online Tutorials Library

    In Python, a dictionary is a built-in data type that stores data in key-value pairs. It is an unordered, mutable, and indexed collection. Each key in a dictionary is unique …

  7. Python Dictionary: Guide to Work with Dictionaries in …

    Learn how to create, modify, and use dictionaries in Python. This tutorial covers all dictionary operations with practical examples for beginners and advanced users.

  8. Dictionaries - Learn Python - Free Interactive Python …

    Learn how to use dictionaries, a data type that stores values using keys instead of indexes. See examples of creating, accessing, iterating and removing …

  9. Python Dictionary (With Examples) - TutorialsTeacher.com

    The dictionary is an unordered collection that contains key:value pairs separated by commas inside curly brackets. Dictionaries are optimized to retrieve values when the key is known.

  10. Python Dictionary Tutorial – Complete Guide to Python Dictionaries

    Learn Python dictionaries from beginner to advanced with examples. Understand dictionary syntax, methods, operations, comprehensions, conversions, and real-world Python dictionary problems.

  11. People also ask
    Loading
    Unable to load answer