Javatpoint Logo
Javatpoint Logo

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.

Signature

Parameters

No parameter

Return

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.

Output:

dict_keys(['name', 'brand', 'price'])

Python Dictionary keys() Method Example 2

Output:

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.

Output:

We have sufficient inventory for the  bananas

Next TopicPython Dictionary





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA