Informatics Practices

Write the output of the following code:

d = { (1,2):1, (2,3):21 }
print (d[1,2] )

Python Dictionaries

2 Likes

Answer

1

Working

In the given code, d is a dictionary that has tuples (1,2) and (2,3) as keys mapped to their respective values 1 and 21. When we access d[1, 2], Python interprets (1,2) as a tuple and looks for this tuple as a key in dictionary d. Therefore, it retrieves the value associated with the key (1,2), which is 1.

Answered By

1 Like


Related Questions