How to print a value for a given key for Python dictionary?

Python dictionary is collection of key value pairs. Value associated with a certain key is returned by get() method.

>>> D1={'a':11,'b':22,'c':33}
>>> D1.get('b')

You can also obtain value by using key inside square brackets.

>>> D1['c']

Updated on: 26-Feb-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started