12_Dictionary in Python
12_Dictionary in Python
Learning objective
• Python Dictionary
• Accessing Values in Dictionary
• Updating Dictionary
• Delete Dictionary Elements
• Properties of Dictionary Keys
• Built-in Dictionary Functions and Methods
Dictionary - Introduction
• A dictionary is a collection of data items which are unordered,
changeable and indexed.
• In Python dictionaries are written with curly brackets, and they
have keys and values.
• Each key is separated from its value by a colon (:), the items are
separated by commas, and the whole thing is enclosed in curly
braces.
• The dictionary values can be of any type, but the keys must be of
an immutable data type such as strings, numbers, or tuples.
• If we attempt to access a data item with a key, which is not part of the
dictionary, we get an error
Updating Dictionary
• You can update a dictionary by adding a new entry or a key-value
pair, modifying an existing entry, or deleting an existing entry.