title: How do I check if a variable exists, inside a Function?
body: <p>I'm trying so check if a variable exists, but inside a function.
  I was taught that, to do this, the only thing you needed to do was:</p>
  
  <pre><code>'a' in locals() 
  </code></pre>
  
  <p>Unfortunately, things turned out to be a little bit more difficult than I expected.</p>
  
  <p>I tried to define a function that included this method.</p>
  
  <pre><code>q=[1,2,3]
  def f():
      print('q' in locals())
  </code></pre>
  
  <p>When I run this function, it returns:</p>
  
  <pre><code>False
  </code></pre>
  
  <p>The problem is, as we can see, that q is a variable, so when I run the same command, but outside the function:</p>
  
  <pre><code>'q' in locals()
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>True
  </code></pre>
  
  <p>Is there a way to solve this?</p>