title: Why do Python defined functions perform faster than global scripts outside the scope of "def"?
body: <p>Okay, so the wording of this question is very hard to say.</p>
  
  <p>However, I have two scripts written in Python 3.5.2:</p>
  
  <pre><code>import time
  t0 = time.clock()
  def hello():
      a = []
      for i in range(10000000):
          a.append(i)
  hello()
  t1 = time.clock()
  print((t1-t0))
  </code></pre>
  
  <p>Out: <code>1.0960211284655088</code></p>
  
  <p>and</p>
  
  <pre><code>import time
  t0 = time.clock()
  a = []
  for i in range(10000000):
      a.append(i)
  t1 = time.clock()
  print((t1-t0))
  </code></pre>
  
  <p>Out: <code>1.432725885821128</code></p>
  
  <p>The first script runs faster being inside a defined function and then called; however, I don't know why this is and I would like to understand so I can learn to optimize code.</p>
  
  <p>This is a question regarding only this particular aspect of Python 3. I know list comprehensions and map() are much, much faster and more pythonic methods of doing this particular iteration.</p>