Access Items
Access Items
Accessing Dictionary items:
I. Accessing single values:
Values in a dictionary can be accessed using keys. We can access dictionary values by mentioning keys either in square brackets or by using get method.
Example:
Output:
II. Accessing multiple values:
We can print all the values in the dictionary using values() method.
Example:
Output:
III. Accessing keys:
We can print all the keys in the dictionary using keys() method.
Example:
Output:
IV. Accessing key-value pairs:
We can print all the key-value pairs in the dictionary using items() method.
Example:
Output: