Why You Must Use Python if main, if name == main?

preview_player
Показать описание
Why You Must Use Python if main or if name == main block?

This Python tutorial is about Python main function, how to use the if `__name__ == '__main__'` syntax, how it works. Also in this Python if main tutorial I show what is `__name__` variable in Python.

The if `__name__ == '__main__'` block checks the value of the `__name__` variable. Each Python module has it. If a Python script was run as the main script of your project the `__name__` variable get the `__main__` as the value. And this if main condition will be evaluated as True.
If a Python script was imported the `__name__` variable get the name of the file as the value. And this Python if main condition will return False.

Python main() function is just the name of a function. And you can use any function you want. But by convention a Python script should have an entry point, and this entry point is the Python main() function, that should be run if Python module executed as the main module of you project.

Shortly: this Python main function tutorial is about why do you need to use it in every Python project.

Follow me @:

The short Python tutorial series in 1 minute.

*** Other Python shorts ***

➥➥➥ SUBSCRIBE FOR MORE VIDEOS ➥➥➥
Red Eyed Coder Club is the best place to learn Python programming and Django:

Why You Must Use Python if main or if name == main block?

#python #pythonshorts #redeyedcoderclub
Рекомендации по теме
Комментарии
Автор

What video should I make next? Any suggestions? Write me in comments!
Follow me @:

Help the channel grow! Please Like the video, Comment, SHARE & Subscribe!

RedEyedCoderClub
Автор

Thank you for the video. Never thought that it can be explained in one minute :)
Great content!

abrikosa
welcome to shbcf.ru