In Python, modules allow for code to loaded into a program only if it is needed. Modules are one of the advanced topics in Python that we won’t spend too much time on, but here are the basics.
If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable name.
Most of your Python programs are fairly small when you are creating solutions to HackerRank type problems.
print("Hello, World!");helloworld.py
If your program is much larger, it might be split into different files to keep it all more organized or readable. All those files might be kept in a folder all together, as a project. But again, this is beyond what you need to know to do HackerRank Python problems.
Modules are also used to import code others have written that you wish to take advantage of. You’ve seen examples of this when we’ve used "import math" to get access to function definitions within the math module. There are millions of chunks of Python you can find and use in your code. A lot of it is used by many, many people, and it’s important to know where the code you use comes from. It can be dangerous to use someone else’s code that isn’t trustworthy.
See https://docs.python.org/3/tutorial/modules.html for more on modules! Look for information on "import" to see how modules interact with your code.