Home >>Python Dictionary Methods >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 | 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. |
fruits = {
"fruit1": "apple",
"fruit2": "banana",
"fruit3": "orange"
}
a = fruits.get("fruit2")
print(a)
colors = {
"color1": "red",
"color2": "blue",
"color3": "yellow"
}
x = colors.get("color3")
print(x)