Posts

Exception Handling

Image
PYTHON EXCEPTION An exception can be defined as an unusual condition in a program resulting in the interruption in the flow of the program. Whenever an exception occurs, the program stops the execution, and thus the further code is not executed. Therefore, an exception is the run-time errors that are unable to handle to Python script. An exception is a Python object that represents an error Python provides a way to handle the exception so that the code can be executed without any interruption. If we do not handle the exception, the interpreter doesn't execute all the code that exists after the exception. Python has many built-in exceptions that enable our program to run without interruption and give the output. These exceptions are given below: Common Exceptions Python provides the number of built-in exceptions, but here we are describing the common standard exceptions. A list of common exceptions that can be thrown from a standard Python program is given below. ZeroDivisionError: ...

Modules

Image
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. Example In this example, we will create a module named as file.py which contains a function func that contains a code to print some message on the console. Let's create the module named as file.py. Here, we need to include this module into our main module to call the method displayMsg() defined in the module named file. LOADING THE MODULE IN OUR PYTHON CODE We need to load the module in our python code to use its functionality. Python provides two types of statements as defined below. The import statement The f...