(Python) get attribute in dict

衡文
1 min readMar 19, 2020

To advoid “Keyerror” when no key in the dictionary. This also can decrease the number to use for loop.

car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
x = car.get("model")print(x)
#result is :
#Mustang

ref:https://docs.python.org/3/library/stdtypes.html#dict.get

--

--