Python Programming

Dictionary in Python

In Programming, Python by Baqir Ali

Dictionary in Python is a type of list that can be index either number or string.

Suppose we want to index them as Sunday, Monday, Tuesday etc.

Using a dictionary to store the temperature of weak days

temp={
    "sunday":30,
    "mondy":31,
    "tuesday":35,
    "wednesday":45,
    "thursday":41,
    "friday":42
}
print(temp["sunday"])

Output: 30

The dictionary showing above has seven entries of the weak separated by commas, each entry consisting of a key, which in this case is a string, and a value, which in this case is a temperature. Each key and its value are separated by a colon. The syntax for accessing the various entries is similar to that of a list, with the key replacing the index number. For example, to find specific day temperature.

Support us by sharing this post