So, I'm aware that, in Python I can do this:
variable_name = other_variable or 'something else'
...and that that will assign 'something else'
to variable_name
if other_variable
is falsy, and otherwise assign other_variable
value to variable
.
Can I do a nice succinct similar thing with a dict:
variable_name = my_dict['keyname'] or 'something else'
...or will a non-existent keyname always raise an error, cause it to fail?
get
methodmy_dict.get('keyname', 'something else')
– Cropdusting