Python dict.pop() Method
The pop() method removes the element with the specified key.
Syntax
dictionary.pop(keyname, defaultvalue)
Parameters
| Parameter | Description |
|---|---|
keyname |
Required. The keyname of the item you want to remove |
defaultvalue |
Optional. A value to return if the specified key does not exist. If this parameter is not specified, and the no item with the specified key is found, an error is raised |
Return Value
The value of the removed item.
Example
Using the pop() method:
Output
Click Run to execute your code
Enjoying these tutorials?