Python Dictionary

Dictionary in python stores data values in key. (together)

A dictionary in python is ordered, unchangeable and do not allow any duplicates.

They are written in curly braces and have keys and values.

 Let us create a dictionary now for a furthermore clarity:

thisdict = {
 “company”: “Prequelcoding”,
  “sub-title”: “Coder’s Space”, 
  “social”: “Instagram”,
          }
print(thisdict)

Access Dictionary:

How to access a dictionary?

If we are given a task to access any line or an item in the python dictionary we can do it just by declaring and calling it in a square bracket.

Let us see how:

thisdict = {
 “company”: “Prequelcoding”,
  “sub-title”: “Coder’s Space”, 
  “social”: “Instagram”,
          }
y = thisdict["social"]

We can call the same by using get() method:


y = thisdict.get("social")





Getting output via get keys method:

 y = thisdict.keys()

This would give me all the items I've declared inside the thisdict variable.


 

Scroll to top