Write the output of the following code
A={10:100,20:200,30:3000,40:4000,50:5000}
print A.items()
print A.keys()
print A.values()
print A.items()
print A.keys()
print A.values()
Answer:
The output of the code is:
[(10, 100), (20, 200), (30, 3000), (40, 4000), (50, 5000)]
[10, 20, 30, 40, 50]
[100, 200, 3000, 4000, 5000]
Explanation:
- The code creates a dictionary object named A in Python.
- The code then uses three methods to access different aspects of the dictionary object: items(), keys(), and values().
- The items() method returns a list of tuples containing the key-value pairs in the dictionary.
- For example, A.items() returns [(10, 100), (20, 200), (30, 3000), (40, 4000), (50, 5000)], which is a list of tuples containing the key-value pairs in A.
- The keys() method returns a list of the keys in the dictionary. For example, A.keys() returns [10, 20, 30, 40, 50], which is a list of the keys in A.
- The values() method returns a list of the values in the dictionary. For example, A.values() returns [100, 200, 3000, 4000, 5000], which is a list of the values in A.
- The code then prints the results of these methods using the print() function.
Therefore, the output of the code is:
[(10, 100), (20, 200), (30, 3000), (40, 4000), (50, 5000)]
[10, 20, 30, 40, 50]
[100, 200, 3000, 4000, 5000]