title: How to Use Global List in different function in Python?
body: <p>I have a function: instanceDetails() in which I am trying to use global variables, global lists are declared in just after class definition.</p>
  <pre><code>class InstanceDescribe:
      #both variables are global
      all_instances_health = [0]          #stores some ids such as ip-address
      all_instances_health_index = [0]    #against the IP address stores health of server
  
      #some code goes here
      
      def instanceDetails():
      
         #some code goes here to find value of instance_role, instanceId and much more which is used as  argument
         if instance_role=='dispatcherpub' or instance_role=='dispatcheraut':
      
          if instanceId in **all_instances_health**:   #checking IP address is in global variable list
              print(&quot;Yes instance in list, so not calling target gp health function&quot;)
              position = **all_instances_health.index(instanceId)**
              instanceDetailsresult_dict[&quot;Health Status&quot;] = **all_instances_health_index[position]**
          else:                                         #if IP address is not there then calling another function and this function returns values
              print(&quot;No instance is not in  list, so calling target gp health function&quot;)
              return_list = target_object.target_gp_health(instanceId,autoscaling_group_name,cross_account_cred_list)
              instanceDetailsresult_dict[&quot;Health Status&quot;] = return_list[0]
  
              **all_instances_health** = return_list[1]
              **all_instances_health_index** = return_list[2]
  </code></pre>
  <p>Now, could you please tell me, where I have to use global keyword so that my function starts working.
  I have tried so many things but getting error such as:
  <em><strong>name 'all_instances_health' is used prior to global declaration</strong></em>
  and after some putting global keyword with list name under if and else block, am getting this error also:
  <em><strong>name 'all_instances_health' is not defined</strong></em></p>
  <p><strong>NOTE: other functionalities are working properly</strong></p>