title: Why python is not following my sequence of print statement calls
body: <p>I am learning python and just tried out the os.walk() function.I am using python 3.4.4 (64-bit) on windows platform.According to my understanding python should execute my statements line by line.</p>
  
  <p>In this code i have iterated over a directory.The directory structure is </p>
  
  <p><a href="https://i.stack.imgur.com/GDQmC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GDQmC.jpg" alt="The directory structure is as shown"></a></p>
  
  <p>I need to print all the files first followed by the directory names.The code written is:</p>
  
  <pre><code>import os
  dir_path = r"D:\\python_os_walk_check"
  
  for root,dirs,files in os.walk(dir_path):
      for file_name in files:
          print(file_name)
      for dir_name in dirs:
          print(dir_name)
  </code></pre>
  
  <p>The ouput printed is:</p>
  
  <pre><code>first_folder
  second_folder
  test1.txt
  test2.txt
  </code></pre>
  
  <p>According to me the output should be:</p>
  
  <pre><code>test1.txt
  test2.txt
  first_folder
  second_folder
  </code></pre>
  
  <p>Where am i going wrong?</p>