title: The construct " if __name__ == '__main__' " in Python
body: <p>I have gone through so many articles regarding this:</p>
  <pre><code>if __name__ == '__main__'
  </code></pre>
  <p>But I didn't get it... I am going to share you code.  What is a more brief explanation?</p>
  <p>I have created one file, &quot;ab.py&quot;:</p>
  <pre><code>def a():
      print('A function in ab file');
  
  a()
  </code></pre>
  <p>The second file is &quot;xy.py&quot;</p>
  <pre><code>import ab
  
  def b():
      print('b function')
  
  def x():
      print ('s');
  
  x()
  
  if __name__ == &quot;__main__&quot; :
      b()
  </code></pre>
  <p>When I execute this code then this output is coming:</p>
  <pre class="lang-none prettyprint-override"><code>A function in ab file
  s
  b function
  </code></pre>
  <p>What does this mean? What is this code actually doing? Why do we implement this? Our code is also working without it.</p>
  <pre><code>if __name__ == &quot;__main__&quot;:
      b()
  </code></pre>