Python Dictionary popitem() Method

Example

Delete the last item from the dictionary:

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

Run Instance

Definition and Usage

The popitem() method deletes the last item inserted into the dictionary. In versions prior to 3.7, the popitem() method deleted a random item.

The item deleted is the return value of the popitem() method, in the form of a tuple. Please see the following example.

Syntax

dictionary.popitem()

Parameter Value

No Parameters

More Examples

Example

The item deleted is the return value of the pop() method:

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

Run Instance