It is common to find code with this form:
def hacer_algo():
print("algo")
if __name__ == "__main__":
hacer_algo()
Instead of, for example:
def hacer_algo():
print("algo")
hacer_algo()
We also notice that the variable __name__
is not initialized by us, but exists in the environment.
- What is the difference?
- Why prefer one over the other?
- What is it and how it works?