title: Why Python module execute only first time codes which are outside function/class code
body: <p>file words.py</p>
  
  <pre><code>def print_word():
      print("Hello Words")
  
  print(__name__) 
  </code></pre>
  
  <p>When I run above code from console :</p>
  
  <pre><code>(base) C:\Users\Desktop\Python&gt;python words.py
  __main__
  
  (base) C:\Users\Desktop\Python&gt;python words.py
  __main__
  
  (base) C:\Users\Desktop\Python&gt;python words.py
  __main__
  
  (base) C:\Users\Desktop\Python&gt;python
  Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; from words import *
  words
  &gt;&gt;&gt; from words import *
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Why during import it execute print only once but while running python words.py it execute print as many time as we execute ?</p>