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

015 Module

A module in Python is a file that can contain variables, functions, and classes, which can be imported and used in different programs. The document illustrates how to define functions in one module (ModuleOne) and call them in another (MyProgram), while controlling output using the __name__ variable to prevent certain prints during import. This allows for cleaner execution of the main program without unintended outputs from the module.

Uploaded by

niazmohammad3121
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)
3 views2 pages

015 Module

A module in Python is a file that can contain variables, functions, and classes, which can be imported and used in different programs. The document illustrates how to define functions in one module (ModuleOne) and call them in another (MyProgram), while controlling output using the __name__ variable to prevent certain prints during import. This allows for cleaner execution of the main program without unintended outputs from the module.

Uploaded by

niazmohammad3121
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