17.1 Module.pdf

(451 KB) Pobierz
Module
A module can contain predefined variable , functions , classes and we use
this things in different programs with the help of import
Modules are nothing but python files . Normal programs can be modules
too
Lets save this program as ModuleOne
And this program as MyProgram
In program ModuleOne we are defining the function and in program
Myprogram we are calling the function ( add , sub )
What happens if we write print function in ModuleOne program??
it will print that function in MyProgram output
If we want to execute only MyProgram.py but not ModuleOne.py(add and
subtract ) print function
For this we can ass print
(__name__)
It means the printing should be done only if its in main . If it is importing
then don’t execute the print function
We can also write
Zgłoś jeśli naruszono regulamin