SoFunction
Updated on 2024-11-14

Tutorial on returning pairs of dictionary elements using the items method in Python

The items() method returns a list of (key, value) tuple pairs of the dictionary.
grammatical

The following is the syntax of the items() method:

()

parameters

  •     NA

return value

This method returns a list of tuple pairs.
(for) instance

The following example shows the use of the items() method.

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" % ()

When we run the above program, it produces the following results:

Value : [('Age', 7), ('Name', 'Zara')]