Learn Python #9 — Yeah Dictionary🐍

Nitin Reddy
2 min readOct 7, 2022

Today we are going to dive deep into the main data structure in Python known as Dictionary.

Not a dictionary of words

What is Dictionary?💡

In Python, a dictionary is a list of key-value pairs.
Ok, let’s take an example.

Creating a Dictionary💡

dictionary_1 = {
'name': 'Nitin',
'age': 34,
'country': 'India'
}

In the above example
name, age, and country are the keys with the corresponding values as Nitin, 34, and India.

Also, we can create a nested dictionary

dictionary_1 = {
'name': 'Nitin',
'age': 34,
'address': {
'street': 'Keshav'
'country': 'India'
}
}

Easy to understand?💡

A dictionary contains

  • unique keys
  • a key can have different types of values like number, string, boolean etc.

This would look similar to an object in JavaScript

Accessing a key’s value💡

dictionary_1 = {
'name': 'Nitin',
'age': 34,
'country': 'India'
}
dictionary_1['name']
// Nitin
dictionary_2 = {
'name': 'Nitin',
'age': 34,
'address': {
'street': 'Keshav'
'country': 'India'
}
}
dictionary_2['address']['street']
// Keshav

To access any value in a dictionary, we need to enclose the key in square brackets []

Conclusion 📗

There are more posts on the way related to the tuples…So keep reading.

Thanks in advance for reading this article…🚀

I am more than happy to connect with you on

You can also find me on

--

--

Nitin Reddy
Nitin Reddy

Written by Nitin Reddy

Trying to improve my writing abilities. Unraveling the World of JavaScript: Navigating the Code with a Developer's Lens 🔍💻

Responses (1)