Have you seen the expression if _name_ == "__main__" in Python and are you wondering how is it used in Python programs?
In this Python tutorial, we go through the usage of _name_ and _main_ in Python.
---------- C H A P T E R S ----------
(00:00:00) The special variable _name_ in Python (pronounced dunder name).
(00:00:36) Print the value of the _name_ variable in the Python shell.
(00:00:57) Print the value of _name_ for the random module.
(00:01:20) Write a sample Python program to clarify the concept of __name__.
(00:03:00) Explain how you can use _name_ in your Python programs.
(00:04:50) Check the value of _name_ using an if statement to prevent the code in a module from being executed when the module is imported.
(00:06:50) Understand the concept of the Python main function.
(00:08:20) Learn how to pass arguments to your Python application using the sys module (specifically sys.argv).
We will see how checking the value of _name_ in Python can be useful when running your program either directly or as a Python module.
You can find the full tutorial on the CodeFatherTech website:
https://codefather.tech/blog/if-name-...
If you want to learn Python have a look at the full list of CodeFatherTech tutorials:
https://codefather.tech/blog/
Happy coding!
На этой странице сайта вы можете посмотреть видео онлайн What is Python name __main__ : Discover Python's Main Function длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь CodeFatherTech 08 Июль 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 1,677 раз и оно понравилось 23 зрителям. Приятного просмотра!