Python Dictionary keys() Method
Python keys() method is used to fetch all the keys from the dictionary. It returns a list of keys and an empty list if the dictionary is empty. This method does not take any parameter. Syntax of the method is given below.
It returns a list of keys. None if the dictionary is empty.
Let's see some examples of keys() method to understand it's functionality.
Python Dictionary keys() Method Example 1
Let's first see a simple example to fetch keys from the dictionary.
dict_keys(['name', 'brand', 'price'])
Python Dictionary keys() Method Example 2
product price is too high
Python Dictionary keys() Method Example 3
We can use this method into our python program. Here, we are using it into a program to check our inventory status.
We have sufficient inventory for the bananas
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week