title: How to access a local variable outside for loop?
body: <p>I am trying to access a variable defined inside an if statement in a for loop, outside the for loop. but I am getting the 'Unbounded Local Error'</p>
  
  <p>I have tried assigning <code>lambdaPriceUsWest2 = None</code> as suggested  here:
  <a href="https://stackoverflow.com/questions/25406399/python-get-variable-outside-the-loop">Python Get variable outside the loop</a></p>
  
  <p>Also, tried specifying <code>global lambdaPriceUsWest2</code> inside if statement with <code>lambdaPriceUsWest2 = None</code> before the code snippet.</p>
  
  <pre><code>for x in range(len(response['PriceList'])):
          priceList=json.loads(response['PriceList'][x])
          if priceList['product']['sku'] == 'DU9X9ZR8C8DYH3Y9':
               lambdaPriceUsWest2= priceListpriceList['product']['sku']['USD']
  
          if priceList['product']['sku'] == 'CVE47QZ9RSF8DTEM':
              lambdaPriceUsEast2= priceListpriceList['product']['sku']['USD']
              break
  
  logger.debug(lambdaPriceUsWest2)
  </code></pre>
  
  <p>Expected Result:
  0.055512 (similar value)</p>
  
  <p>Actual Result :
  Error: </p>
  
  <pre><code>"errorMessage": "local variable 'lambdaPriceUsWest2' referenced before assignment",
    "errorType": "UnboundLocalError"
  </code></pre>