You missed the canonical method, dict.get():
color_1 = data.get('color')
It’ll return None if the key is missing. You can set a different default as a second argument:
color_2 = data.get('color', 'red')
You missed the canonical method, dict.get():
color_1 = data.get('color')
It’ll return None if the key is missing. You can set a different default as a second argument:
color_2 = data.get('color', 'red')