PP Unit-Iii
PP Unit-Iii
Modules
Exception
Handling
Topics to be covered:
Modules:
Importing module,
Math module,
Random module,
Packages
Exception Handling:
Exception,
Exception Handling,
Except clause, Try? Finally clause User Defined
Exceptions
A group of lines with some name is called a
Function.
A group of functions saved to a file, is called
Module
A group of Modules is nothing but Library.
Python module is but a piece of code.
Exiting the interpreter destroys all functions and
variables we created. But when we want a longer
program, we create a script.
With Python, we can put such definitions in a file, and
use them in a script, or in an interactive instance of the
interpreter. Such a file is a module.
A python module can be defined as a python program
file which contains a python code including python
functions, class, or variables.
In other words, we can say that our python code file
saved with the extension (.py) is treated as the module.
We may have a runnable code inside the python module.
Modules in Python provides us the flexibility to organize
the code in a logical way.
To use the functionality of one module into another, we
must have to import the specific module.
A group of functions, variables and classes
saved to a file, which is nothing but module.
Every python file(.py) acts as module.
from…import:
We can import particular members of module by
using from…import.
The main advantage of this is we can access
members directly without using module name.
We can import all members of a module import*
from Demo import*