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!
Auf dieser Seite können Sie das Online-Video What is Python name __main__ : Discover Python's Main Function mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CodeFatherTech 08 Juli 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,677 Mal angesehen und es wurde von 23 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!