A Python file can either be run as a program or it can be imported by another Python file as a library. `if __name__ == "__main__":` means "only run the following code, if this file was run as a program - not imported as a library".
This is useful if … Read More
You can name your function anything you want, but the name has to be `"__main__"`. That's not about the function being called. `"__main__"` is simply the value that `__name__` gets if the Python file is invoked directly instead of being imported.
PS: Calling your function both inside and outside of … Read More
> so the if statement isn't required?
You only need the if statement if you want your code to act differently depending on whether it's imported or run as a program.
> what is the `__name__` by default?
If the Python file is run as a program (i.e. using `python … Read More
> I think import can be used to access functions from another .py file but I'm not sure and haven't used it yet
Yes and here dos `if __name__ == "__main__":` play and important part.
You have made a fantastic name multiplier code,and you whant to import it so you … Read More
> can I import a file from the very same folder as the file I want to run?
Yes, this is one way Python can find the import file. Read More
It will not import both. When you import a module it searches through the available modules and imports the first one it finds with the given name. The order in which it goes through the modules is explained [in this section of the docs](http://docs.python.org/2/tutorial/modules.html#the-module-search-path):
> When a module named spam … Read More
A common mistake beginners make is to name their code/script file the same as a Python module they need to import. For instace random.py will screw up the random module. Read More