-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaries_get().py
More file actions
41 lines (29 loc) · 844 Bytes
/
Dictionaries_get().py
File metadata and controls
41 lines (29 loc) · 844 Bytes
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
# Python Dictionary get() Method
# Example
# Get the value of the "model" item:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")
print(x)
# Definition and Usage
# The get() method returns the value of the item with the specified key.
# Syntax
# dictionary.get(keyname, value)
# Parameter Values
# Parameter Description
# keyname Required. The keyname of the item you want to return the value from
# value Optional. A value to return if the specified key does not exist.
# Default value None
# More Examples
# Example
# Try to return the value of an item that do not exist:
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("price", 15000)
print(x)