Javatpoint Logo
Javatpoint Logo

Python Dictionary items() Method

Python item() method returns a new view of the dictionary. This view is collection of key value tuples. This method does not take any parameter and returns empty view if the dictionary is empty. The examples and syntax are given below.

Signature

Parameters

No parameter

Return

It returns a dictionary's view.

Let's see some examples of items() method to understand it's functionality.

Python Dictionary items() Method Example 1

This is a simple example which returns all the items present in the dictionary.

Output:

dict_items([('name', 'rohan'), ('course', 'B.Tech'), ('email', 'rohan@abc.com')])

Python Dictionary items() Method Example 2

If the dictionary is already empty, this method does not raise any error. See the example below.

Output:

dict_items([])

Python Dictionary items() Method Example 3

Apart from items() method, we can also use other customized approaches to fetch dictionary elements. See an example below.

Output:

( name : rohan), ( course : B.Tech), ( email : rohan@abc.com), 
 dict_items([('name', 'rohan'), ('course', 'B.Tech'), ('email', 'rohan@abc.com')])

Next TopicPython Dictionary




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA