Way for see if dict has a key
looping
kadeko at gmail.com
Fri Jun 30 07:35:33 EDT 2006
Michele Petrazzo wrote:
> Bruno Desthuilliers wrote:
> >> but what the better
> >
> > Depends on the context.
> >
>
> If know only one context: see if the key are into the dict... What other
> context do you know?
>
> Michele
Why do you want to do that ?
if key in dict:
value = dict[key]
else:
value = None
could be write:
try:
value = dict[key]
except KeyError:
value = None
so depends of the context...
More information about the Python-list
mailing list