title: Modify global list inside a function
body: <p>First of all, I understand that I can use <code>global</code> statement to access global variables. But somehow I was able to modify a global list without <code>global</code> like below:</p>
  <pre><code>def func1(nums):
      nums = [4,5,6]
  
  nums = [1,2,3]
  func1(nums)
  print nums # print [1,2,3]
  
  def func2(nums):
      nums[0] = 4
      nums[1] = 5
      nums[2] = 6
  
  nums = [1,2,3]
  func2(nums)
  print nums # print [4,5,6]
  </code></pre>
  <p>After trying func2, I realized that I can always access global list in a function if I specify the index:</p>
  <pre><code>def func3(nums):
      nums[:] = [4,5,6]
  
  nums = [1,2,3]
  func3(nums)
  print nums # print [4,5,6]
  </code></pre>
  <p>Is it because Python automatically goes trying to match a global variable if a function variable is used before definition?</p>