title: Can I change variables outside of a for loop from within a for loop in python?
body: <p>I'm trying to write a program which counts the times in a list where an item is greater than their adjacent neighbours on either side:</p>
  
  <pre><code>inp = [1, 2, 3, 2, 8, 7, 6, 9, 5]
  
  def check(n):
      count = 0
      ind_num1 = 0
      ind_num2 = 2
      index1 = n[ind_num1]
      index2 = n[ind_num2]
      for i in n[1:-1]:
          if i &gt; index1 and i &gt; index2:
              count += 1
          ind_num1 += 1
          ind_num2 += 1
      return count
  
  print(check(inp))
  </code></pre>
  
  <p>My solution is to check whether value in the for loop (<code>i</code>) is greater than the indexes above and below it, while adding one to each adjacent index each time through the loop. <code>ind_num1</code>  and <code>ind_num2</code> show the correct values as the loop progresses. However, <code>index1</code> and <code>index2</code> remain the same instead of incrementally increasing in line with the value of <code>ind_num1</code> and `ind_num2'. Why don't they change?</p>