Using 'in' with a Dict

cpmcdaniel at gmail.com cpmcdaniel at gmail.com
Wed Feb 16 16:43:42 EST 2005


I was wondering if the following two "if" statements compile down to
the same bytecode for a standard Dictionary type:

m = {"foo": 1, "blah": 2}

if "foo" in m:
  print "sweet"

if m.has_key("foo"):
  print "dude"




More information about the Python-list mailing list