Python dictionaries, key existence with fallback

Viewed 7262

Is there any difference, gotcha or disadvantage between these approaches?

foo = dict(key=u"")
bar = foo.get('key', 'foobar')

vs

foo = dict(key=u"")
bar = bool(foo['key']) or 'foobar'
6 Answers
Related