Read and Writing File

In the previous blog, we took a brief look at the concept of File Handling in Python as well as how to open a file in Python. In this blog, we will cover how we can read from a file, append to a file and write to a file. Remember, we will be using the…

File Handling

File Handling Python, like most programming languages, allows us to work with files directly from Python. Using Python we can read files stored in a file, as well as alter it, remove contents, or add more to it. We do not have to use any particular module to work with files. Python offers certain functions…

finally and raise

In this blog let us consider the Finally and Raise statements that we mentioned in the previous blog. Finally The Finally statement executes whether or not there is an error in the code or not. We can use Finally to make sure we clean up the resources that we use. Remember, we can use Try…

try and except

Let us look at an example of a program that adds 15 to the user’s input. def add_function(number):     print(type(number))     print(“”)     number = int(number)     print(number + 15) user_input = input(“Enter a number: “) add_function(user_input) The program must convert the user’s input into an integer type, as the type…

Introduction to Error handling

Error Handling When we work with Python, especially during the phase where we test our code, we are sure to face an error or more. Using Error Handling we have a way to modify the way Python should respond if there is an error, this is exponentially useful as the default method of responding to…

Polymorphism

Polymorphism  A fundamental concept in OOP is Polymorphism and a child class can give a complete makeover to a function that it inherited from its parent class. The term Polymorphism refers to the idea of having many forms. Before we get into an example, let’s examine two in-built polymorphous functions that we used. # The…

Method of Overriding

Method Overriding In OOP, we use Method Overriding or also known as Function Overriding, to override a function that exists in the parent class. In Inheritance, we can use Function Overriding to create a unique child class that reuses existing code with modifications to selected portions of our code. This is a powerful concept that…

Access Modifiers

Access Modifiers Through object-oriented programming, Python gives us the ability to control Access Modifiers which allow us to restrict the access of selected variables and functions within a class or an object. There are 3 Access Modifiers that we can use and they are common for most programming languages, they are: Public Protected Private Access…

Inheritance

Inheritance Inheritance is the concept of creating a new class by reusing an existing class which allows us to get rid of repetitious code and allows us to modify properties from the “parent” (or original) class or add a specific property that will be unique to each “child” (or derived) class. We use the terms…

Concept of Constructor and Destructors

Constructors Constructors are a crucial part of OOP and are functions that get executed when we instantiate an object of a class. We can use this to our advantage to initialize desired values for an object. We used constructors in our earlier code, which is the __init__() function. Consider an example class Test_Function: def __init__(self,…