title: Global Variable Python
body: <pre><code>A=[]
  
  def main():
      global A
      A=[1,2,3,4,5]
      b()
  
  def b():
      if(len(A)&gt;0):
          A=[7,8,9]
      else:
          if(A[3]==4):
              A.remove(2)
  
  main()  
  </code></pre>
  
  <p>This code gives error in line A.remove(2) giving reason:"UnboundLocalError: local variable 'A' referenced before assignment"</p>
  
  <p>but A list is global and for sure it has been initialized in main() function.Please explain why this is giving error?</p>
  
  <p>As A has been initialized again in b function, will this cause error?</p>