Thread Object
Thread Object In the previous blog we used an object of the class Thread to create and start a thread, as shown below: variable = threading.Thread(target=function_name, args=[1]) Let us take a closer at the Thread class. The most frequently used aspect of the threading module is the Thread class. The Thread class allows us to…
Threading Module in Python
Threading Let us explore the Threading module. Firstly let’s look at an example of how much time a code takes to run when we do not use threading and when we do use threading. import time # starting a counter start = time.perf_counter() def sleeper_function(sleep_length): print(“Going to sleep now:”) time.sleep(sleep_length) …
Introduction to Multithreading
Multithreading When we run a block of code, let’s say a ‘While’ loop, the program is now halted till this loop has reached completion. In other words, we cannot execute two blocks of code simultaneously. To achieve multitasking using programming we need to use threading, or specifically Multithreading. The concept of threading allows us…
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…