Python Dictionary items() Method

Example

Return the key-value pairs of the dictionary:

car = {
  "brand": "Porsche",
  "model": "911",
  "year": 1963
}
x = car.items()
print(x)

Run Instance

Definition and Usage

The items() method returns a view object. This view object contains the key-value pairs of the dictionary, in the form of tuples in a list.

The view object will reflect any changes made to the dictionary, please see the following example.

Syntax

dictionary.items()

Parameter Value

No Parameters

More Examples

Example

When the value of an item in the dictionary changes, the view object will also be updated:

car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
x = car.items()
car["year"] = 2018
print(x)

Run Instance