-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dictionaries_pop().py
43 lines (30 loc) · 984 Bytes
/
Dictionaries_pop().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Python Dictionary pop() Method
# Example
# Remove "model" from the dictionary:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
car.pop("model")
print(car)
# Definition and Usage
# The pop() method removes the specified item from the dictionary.
# The value of the removed item is the return value of the pop() method, see example below.
# Syntax
# dictionary.pop(keyname, defaultvalue)
# Parameter Values
# Parameter Description
# keyname Required. The keyname of the item you want to remove
# defaultvalue Optional. A value to return if the specified key do not exist.
# If this parameter is not specified, and the no item with the specified key is found, an error is raised
# More Examples
# Example
# The value of the removed item is the return value of the pop() method:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.pop("model")
print(x)