DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Learn Python #9 - Yeah Dictionary🐍
Nitin Reddy
Nitin Reddy

Posted on

Learn Python #9 - Yeah Dictionary🐍

Today we are going to deep dive 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'
}
Enter fullscreen mode Exit fullscreen mode

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'
  }
}
Enter fullscreen mode Exit fullscreen mode

Easy to understand?πŸ’‘

A dictionary contains

  • unique keys
  • 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
Enter fullscreen mode Exit fullscreen mode

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

think

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

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.