title: Determine whether a key is present in a dictionary
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1323410/has-key-or-in">&#39;has_key()&#39; or &#39;in&#39;?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a Python dictionary like :</p>
  
  <pre><code>mydict = {'name':'abc','city':'xyz','country','def'}
  </code></pre>
  
  <p>I want to check if a key is in dictionary or not.
  I am eager to know that which is more preferable from the following two cases and why?</p>
  
  <pre><code>1&gt; if mydict.has_key('name'):
  2&gt; if 'name' in mydict:
  </code></pre>