Site icon New Generation Enterprise Linux

Dictionaries in Python

Today we will see another data structure that can be defined in Python known as dictionary.

As its name suggests, we keep the “key:value” pairs in this datatype.

Let us see a small program to understand it.

Program

#### Dictionaries
month_dict = {
    "1" : "Jan",
    "2" : "Feb"

}

print(month_dict.get("1"))

 

Output
As we can see below “Jan” is printed i.e. the value corresponding to key value “1”.

/Users/saket/PycharmProjects/1helloworld/venv/bin/python /Users/saket/PycharmProjects/1helloworld/calculator.py
Jan

Process finished with exit code 0

 

0 0 votes
Article Rating
Exit mobile version