title: What is a good practice to check if an environmental variable exists or not?
body: <p>I want to check my environment for the existence of a variable, say <code>"FOO"</code>, in Python. For this purpose, I am using the <code>os</code> standard library. After reading the library's documentation, I have figured out 2 ways to achieve my goal:</p>
  
  <p>Method 1:  </p>
  
  <pre><code>if "FOO" in os.environ:
      pass
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>if os.getenv("FOO") is not None:
      pass
  </code></pre>
  
  <p>I would like to know which method, if either, is a good/preferred conditional and why.</p>