Python Dictionary pop() method

The dictionary.pop() method in removes the specified item and returns an element from a dictionary having the given key.

Syntax

Parameter

key – This argument signifies the key which is to be searched for removal.

default – This parameter represents the value which is to be returned when the key is not in the dictionary.

Return

This method removes and returns an element from a dictionary if the key is found else a KeyError exception is raised if the key if not found and the default argument is not specified.

Example 1

Output

Example 2

Output

Example 3

Output

Pin It on Pinterest

Share This