What is the meaning of __name__ == "__main__" in Python?

Why __name__ == "__main__" is used as a condition in python.

When a file executes it sets some special variables and __name__ is one of them. __name__ is set as "__main__" if it is getting executed directly. But if the file has been imported then it stores the filename suppose.

For example:

abc.py:

if __name__ == "__main__":
    print("Executed directly", __name__ )
else
    print("Import executed", __name__ )

### On execution of abc.py directly __name__ will store "__main__".

xyz.py:

import abc
print "Import executed: ", __name__  

### On execution of xyz.py, below output will display:

Import executed abc.py
Import executed __main__