title: understanding the execution flow in python
body: <p>Being new to python, confused with the flow of execution:</p>
  
  <p>To elaborate I am stating the below examples:</p>
  
  <p><strong>Example 1:</strong> </p>
  
  <pre><code>def hello():
      print("hello world")
      python()
  
  def python():
      print("testing main")
  
  if __name__ == "__main__":
      hello()
  
  **output :**
      hello world
      testing main
  </code></pre>
  
  <p>NOTE : I am aware of usage of <strong>__name__ == "__main__".</strong></p>
  
  <p><strong>Example 2:</strong></p>
  
  <pre><code>python()
  
  def python():
      print("testing main")
  
  **output**
  File "main_flow.py", line 2, in &lt;module&gt;
  python()
  NameError: name 'python' is not defined
  </code></pre>
  
  <p>As far as I know python executes the program in sequential manner(correct me if I am wrong), hence in Example 2 it is not able to find the method python() when it encounters it.</p>
  
  <p>My confusion is why in example 1 the similar error has not occured, what is the flow of execution in this scenario.</p>