Hey Luca. Thanks for taking the time to help me out.
Nice explanation.
It also indicates the starting point of the script when executing script_1.py on its own.
I had actually thought of saying it like this, but then I doubted if it was really very correct since it kinda implies that it has to be there because it's the starting point of the execution. If I was a complete beginner, I'd take that to mean that a program without that part wouldn't run since the script doesn't have a starting point to execute from.
Here's what I mean. Consider this code for example:
defhello():print("hello!")hello()
The code works just fine without the if __name__ == '__main__':. What's the starting point of the script when executing that code on its own?
Maybe I'm overthinking it? 😅
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Luca. Thanks for taking the time to help me out.
Nice explanation.
I had actually thought of saying it like this, but then I doubted if it was really very correct since it kinda implies that it has to be there because it's the starting point of the execution. If I was a complete beginner, I'd take that to mean that a program without that part wouldn't run since the script doesn't have a starting point to execute from.
Here's what I mean. Consider this code for example:
The code works just fine without the
if __name__ == '__main__':
. What's thestarting point of the script
when executing that code on its own?Maybe I'm overthinking it? 😅