Python Dictionary popitem() Method Tutorial

In this section we will learn what the Dictionary popitem() method is and how to use it in Python.

What is Dictionary popitem() Method in Python?

The Python dictionary popitem() method is used to remove the last entry (the last pair of key, value) that was inserted into the target Dictionary object.

This method then returns that last entry in a tuple object with the first item being the key and the second item will be the value of that key.

Python Dictionary popitem() Method Syntax:

set.popitem()

Dictionary popitem() Method Parameter:

The method does not take an argument.

Dictionary popitem() Method Return Value

The return value of this method is a Tuple object with its first item being the key and its second item is the value of the last entry of the target dictionary.

Example: using python dictionary popitem() method

dictionary = {

"name":"John",

"lastName":"Doe"

}

print(dictionary.popitem())

Output:

('lastName', 'Doe')
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies