Question:

What is a Dictionary in Python? Show how you create a dictionary, access its items and find its length.

Show Hint

Dictionary keys must be unique, but values can be repeated.
Updated On: Mar 14, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Define Dictionary.

A dictionary in Python is a data structure used to store data in key–value pairs. Each key is associated with a value, and keys must be unique within the dictionary.

Dictionaries are unordered collections and are written using curly braces {}.

Step 2: Creating a Dictionary.

A dictionary can be created by assigning key–value pairs inside curly braces.

Example:

student = {"name":"Rahul", "age":20, "marks":85}
Here name, age, and marks are keys and their associated values are Rahul, 20, and 85.

Step 3: Accessing Dictionary Items.

Dictionary values can be accessed using their keys.

Example:

print(student["name"])
This prints the value associated with the key name.

Step 4: Finding the Length of a Dictionary.

The length of a dictionary can be determined using the len() function.

Example:

len(student)
This returns the total number of key–value pairs in the dictionary.

Step 5: Conclusion.

Thus dictionaries store data in key–value pairs and allow efficient data retrieval using keys.
Was this answer helpful?
0
0