title: Python Get variable outside the loop
body: <p>I have a python code ,i need to get its value outside the for loop and if statements and use the variable further:</p>
  
  <p>My code:</p>
  
  <pre><code>with open('text','r') as f:
    for line in f.readlines():
        if 'hi' in line
           a='hello'
  
  print a  #variable requires outside the loop
  </code></pre>
  
  <p>But i get <code>Nameerror: 'a' is not defined</code></p>