Home >>Python Dictionary Methods >Python Dictionary get() Method

Python Dictionary get() Method

Python Dictionary get() Method

Python Dictionary get() Method in python returns the value for the given keys. It returns default value none if keys is not exist.

Syntax:
dictionary.get(keyname, value)

Parameter Values

Parameter Description
keyname It is Required. The keyname of the item you want to searched in the dictionary
value It is Optional. Default value is none when the keys does not exist.
Here is an Example Python Dictionary get() Method:

fruits = {
"fruit1": "apple",
"fruit2": "banana",
"fruit3": "orange"
}
a = fruits.get("fruit2")
print(a)

Output:
banana
Example 2:

colors = {
"color1": "red",
"color2": "blue",
"color3": "yellow"
}
x = colors.get("color3")
print(x)

Output:
yellow

No Sidebar ads