Informatics Practices
Write the output of the following code:
d = {'a':1, 'b':2, 'c':3}
print (d['a'])
Python Dictionaries
3 Likes
Answer
1
Working
In the above code, d is a dictionary initialized with keys 'a', 'b', and 'c', each mapped to their respective values 1, 2, and 3. When print(d['a']) is executed, Python retrieves the value associated with the key 'a' from dictionary d. Therefore, the output of print(d['a']) will be 1.
Answered By
2 Likes
Related Questions
What is the output produced by the following code :
d1 = {5 : [6, 7, 8], "a" : (1, 2, 3)} print(d1.keys()) print(d1.values())Write the output of the following code:
d = { (1,2):1, (2,3):21 } print (d[1,2] )Write a program to input your friends' names and their phone numbers and store them in a dictionary as the key-value pair. Perform the following operations on the dictionary:
(a) Display the Name and Phone numbers of all your friends.
(b) Add a new key-value pair in this dictionary and display the modified dictionary.
(c) Delete a particular friend from the dictionary.
(d) Modify the phone number of an existing friend.
(e) Check if a friend is present in the dictionary or not.
(f) Display the dictionary in sorted order of names.
Consider the following dictionary Prod_Price.
Prod_Price = {'LCD' : 25000, 'Laptop' : 35000, 'Home Theatre' : 80000, 'Microwave Oven' : 18000, 'Electric Iron' : 2800, 'Speaker' : 55000}Find the output of the following statements:
(a) print(Prod_Price.get('Laptop'))
(b) print(Prod_Price.keys())
(c) print(Prod_Price.values())
(d) print(Prod_Price.items())
(e) print(len(Prod_Price))
(f) print('Speaker' in Prod_Price)
(g) print(Prod_Price.get('LCD'))
(h) del ProdPrice['Home Theatre'] print (ProdPrice)