key not found in dictionary

Simon Forman rogue_pedro at yahoo.com
Tue Aug 22 21:17:21 EDT 2006


> Or you can use the has_key() and test it first. For example
>
>   if foo.has_key('bar'):
> 	print 'we have it'
>   else :
> 	print 'we don't have bar.'
> 

Nowadays you can also say:

if 'bar' in foo:
    # do something




More information about the Python-list mailing list