0% found this document useful (0 votes)
6 views2 pages

Module

A module in Python can contain predefined variables, functions, and classes, allowing them to be reused in different programs through import. The document illustrates this by defining functions in one module (ModuleOne) and calling them in another program (MyProgram), while explaining how to control output using the __name__ variable. This ensures that certain print statements only execute when the module is run as the main program, not when it is imported.

Uploaded by

skillsmatters432
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Module

A module in Python can contain predefined variables, functions, and classes, allowing them to be reused in different programs through import. The document illustrates this by defining functions in one module (ModuleOne) and calling them in another program (MyProgram), while explaining how to control output using the __name__ variable. This ensures that certain print statements only execute when the module is run as the main program, not when it is imported.

Uploaded by

skillsmatters432
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module

• A module can contain prede ned variable , functions , classes and we use
this things in di erent programs with the help of import
• Modules are nothing but python les . Normal programs can be modules
too


• Lets save this program as ModuleOne


• And this program as MyProgram

• In program ModuleOne we are de ning the function and in program


Myprogram we are calling the function ( add , sub )
• What happens if we write print function in ModuleOne program??
ff
fi
fi
fi
• it will print that function in MyProgram output
• If we want to execute only [Link] but not [Link](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

You might also like