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!
On this page of the site you can watch the video online What is Python name __main__ : Discover Python's Main Function with a duration of hours minute second in good quality, which was uploaded by the user CodeFatherTech 08 July 2021, share the link with friends and acquaintances, this video has already been watched 1,677 times on youtube and it was liked by 23 viewers. Enjoy your viewing!