CBSE Class 11 Computer Science Question 24 of 112

Dictionaries — Question 4

Back to all questions
4
Question

Question 4

Which of the following functions will return the key, value pairs of a dictionary ?

  1. keys( )
  2. values( )
  3. items( )
  4. all of these
Answer

items( )

Reason — items() method is used to return the list with all dictionary keys with values.
For example:

d = {'a':2, 'b':5} 
print(d.items())
Output

dict_items([('a', 2), ('b', 5)])