How to test if a key in a dictionary exists?

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat Mar 10 22:23:49 CET 2007


Frank wrote:
> Hi,
> 
> does anyone know how one can test if, e.g., a dictionary 'name' has a
> key called 'name_key'?

name_key in name

e.g.

 >>> name={"john": 42}
 >>> "john" in name
True
 >>> "julie" in name
False

--Irmen



More information about the Python-list mailing list