__name__ (Special Variable):

As there is no main() function in Python for data science. The code at level 0 indentation gets execute when we give the command for a program to run. Some special variables are considerdc before execution. __name__ is a special variable. When the source file executes as the main program, the interpreter sets the __name__ variable to have a value “__main__”. If the file is import from a different module, __name__ is set to the module name.

__name__ is a built-in variable evaluating to the name of the current variable. When we have to check whether the current script is run on its own or it has been import from somewhere else with the help of if statement, it is useful

python code for data science

name code for data science

In the above example we observe that in case of File1.py, the interpreter sets the __name__ variable as __main__. In case of File2.py which is run through importing File1.py the interpreter sets the __name__ variable as File1.

To learn more about name function in python for data science, you can check this and this.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.