Python Moudule
Modules are used to categorize code in Python into smaller part. A module is simply a file, where classes, functions and variables are defined. Grouping similar code into a single file makes it easy to access.
Have a look over example:
If the content of a book is not indexed or categorized into individual chapters, then the book might have turned boring and hectic. Hence, dividing book into chapters made it easy to understand.
In the same sense python modules are the files which have similar code. Thus module is simplify a python code where classes, variables and functions are defined.
Advantage:
Python provides the following advantages for using module:
1) Reusability: Module can be used in some other python code. Hence it provides the facility of code reusability.
2) Categorization: Similar type of attributes can be placed in one module.
Importing a Module:
There are different ways by which you we can import a module. These are as follows:
1) Using import statement:
"import" statement can be used to import a module.
Syntax:
Have a look over an example:
eg:
Save the file by the name addition.py. To import this file "import" statement is used.
No comments:
Post a Comment