You can access dictionary keys and values in Python using the following syntax:
main.py275 chars15 lines
Output:
main.py128 chars5 lines
In the example above, the keys() method returns a list of all keys in the dictionary. The values() method returns a list of all values in the dictionary. The items() method returns a list of key-value pairs in the dictionary. You can access the value of a specific key in the dictionary by using the key in square brackets like my_dict['apple']. Here, it will return the value of key 'apple' which is 10.
gistlibby LogSnag