support@vlsimaster.com
Facebook
Instagram
Linkedin
Home
Learnings
Frontend
C
C++
Verilog
System Verilog
Backend
STA
Placement
Floor Planning
Scripting
Python
Perl
Account
Register
Login
Register as a Recruiter
More
Q&A
FAQ
About us
Contact us
Menu
Home
Learnings
Frontend
C
C++
Verilog
System Verilog
Backend
STA
Placement
Floor Planning
Scripting
Python
Perl
Account
Register
Login
Register as a Recruiter
More
Q&A
FAQ
About us
Contact us
Home
Learnings
Frontend
C
C++
Verilog
System Verilog
Backend
STA
Placement
Floor Planning
Scripting
Python
Perl
Account
Register
Login
Register as a Recruiter
More
Q&A
FAQ
About us
Contact us
Menu
Home
Learnings
Frontend
C
C++
Verilog
System Verilog
Backend
STA
Placement
Floor Planning
Scripting
Python
Perl
Account
Register
Login
Register as a Recruiter
More
Q&A
FAQ
About us
Contact us
Christopher Jacob Samuel
Author of Python Blogs| Data Science Engineer
Introduction to Python
Getting Started with Python Python is such an interesting language to learn and I know you are excited but before we get started, let’s have a quick discussion of what exactly is Python. Python is a dynamically typed language that was created with code-readability in mind. Too much? Let’s break it down. Let us take...
Numbers
Types of Numbers We are well aware of different types of numbers, such as integers, real numbers, decimals, whole numbers, etc. In Python, we have 3 different numeric types to work with. They are integers (referred to as int), floating-point numbers (referred to as float), and complex numbers. Integers are the standard numbers we use...
Math Functions
Math Module A Python module that provides access to mathematical functions. In other words, it is a library that we can bring in, to use functions defined within it. If you do not know what a function is, simply put it is a block of code that can be invoked at any time without having...
Operators, Relational and Logical Opertaors
Operators We were often asked by our teachers in younger classes what is the sum/difference of two numbers and as we grew up, we were asked logical concepts such as is 100 > 99? This is the foundation of programming; we manipulate all these logical expressions using operators, how operands relate to each other, and...
Variables
Comments Before we begin let us consider comments in Python. You must have noticed how I used the ‘#’ to convey certain information. When Python sees a ‘#’ it skips that line or part of code. We use comments to convey some information to those who read our code. # This variable was obtained from...
Modules and Function
Functions Previously, we discussed the basic idea of a function. In this blog, we will learn in-depth about functions and how to create them. FACT: We have been using a function consistently since the first blog, and that is the ‘print()’ function which to be specific is one of Python’s built-in functions. Functions are a...
Input and Output
Input Let’s write a program that depends on a value provided by the user. To take input from the user, Python provides us with the “input()” function which halts a program till a user provides input. user_name = input("Enter your name: ") print("Welcome to Verification Master,", user_name) The input() function has a parameter called “prompt”,...
Data Types
Data Types We explored the numeric data types when we talked about numbers in Python. However, there is a whole range of data types that we can use in Python, and in this blog, we’ll explore some of the most commonly used data types. What exactly is a data type? It refers to the different...
String
Strings in Python In the previous blog Data Types, we explored Strings in Python, and in this blog let’s dig a bit deeper into strings and what we can do with them. A string in Python is an array (or list) of characters, and in Python, a single character is still considered as a string...
Lists
Lists in Python We were introduced to the list data type in an earlier blog, and in this blog, we will explore the different ways to use a list. Consider the following example: list_variable = ["Python", "Dynamically Typed", "Programming Language"] Accessing items in a List To select an item from the list you simply add...
Tuples
Tuples Let’s look back to tuples and dive deeper into a topic we briefly brushed in an earlier blog. Consider the following: tuple_variable = ("Laptops", "Mobiles", "Game Consoles", "Television", "Smart Watches") Accessing items in a Tuple An item within a tuple can be accessed the same way we would access a list’s item. print(tuple_variable[2]) #...
Conditional Statment
Conditional Statements When we talked about operators, we talked about how manipulating logical expressions are the building block of programming. In this blog, we will explore conditional statements, which essentially are us telling the computer to do a certain computation or execute this block of code, if a particular condition is satisfied. If Statement The...
Looping
Looping In the earlier blogs we used a “For Loop” to iterate (or explore) through items in a collection and in this blog, we will explore the two different kinds of looping mechanisms that we can use in Python. The two types of loops in Python are: For Loop While Loop NOTE: Don’t forget that...
Modularity, Reusability, and Anonymous Functions
Modularity and Reusability Building on what we have learned so far, consider a comprehensive program that allows us to shop for fruits and vegetables. Here we have 3 Python files named “main.py”, “fruits.py”, and “vegetables.py” and all of these are stored in a separate folder called “Shopping_Module”. Here the main.py will have code that works...
Global Local and Nonlocal Variables
Variables are storehouses for values that we wish to use to achieve with programming. Defining variables also helps us to define the nature of operations for which we can use them. Global & Local Variables variable_1 = 5 # global variable def function_test(): variable_2 = 10 # local variable print("variable_1 inside is", variable_1) print("variable_2 inside...
Regular Expressions
Regular Expressions Regular Expressions (also well known as regex) allow us to search for a particular textual pattern. We use different kinds of symbols to create a regular expression, however, these symbols are universal for all programming languages. Using regex, some of the things we can ask Python to check is if the text has:...
Sets
Let us consider another type of data in Python which is called “Sets”. Like Lists, Tuples, & Dictionaries, Sets also provide us a way to store a collection of items but have their unique properties. Let’s look at an example of a Set: set_variable = {"Python", "Dynamically Typed", "Programming Language"} Accessing items of a Set...
Introduction to OOP
Introduction to OOP OOP stands for Object-Oriented Programming; it is a programming paradigm (or concept) that is aimed at making our program more readable and structured by grouping together all of the related variables and functions into a class. A class provides a blueprint of related variables and functions, and we create an object or...
Map, Filter & Reduce
We learned about anonymous functions, but let’s explore 3 of Python’s most powerful anonymous functions and these are map(), filter(), and reduce(). These 3 enable us to approach programming with a functional paradigm {which is another way of saying we use functions}. Map We can use the map() function to use all of the provided...
Classes
Classes We explored OOP in an earlier blog and we touched on classes, so in this blog let’s explore classes in a greater length. Classes provide a way to package together data types and methods or functions, that are interrelated. Let’s consider the syntax of creating a class: class <class_name>: ….–code— class First_Class: variable1 =...
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,...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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) ...
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...
Lock and Rlock Object
Lock Another important feature that we need to remember when using Threads is the mechanism of locking. Imagine if you are using multiple threads on a single resource, when one thread updates the shared resource, another thread may also make some modifications to the shared resource. For example, imagine if multiple employees are using a...
Event and Timer Object
Event When using Threads there are situations when we want the thread to wait for some time and then continue execution. We can achieve this with the use of the Event object. An event is signaled from one thread while another waits for the event to be signaled. One of the aims of using an...
Condition Object
Condition The condition object allows us to run a thread only if a requirement is met in another thread, and once it’s met, we can inform the waiting thread that the requirement has been met. A real-life scenario of this would be; that a producer has run out of products in his store, now the...
Barrier Object
Barrier The Barrier object allows us to make two or more threads wait till a certain condition has been met. We achieve this using the wait() function, and each of the threads tries to pass over the wait() function but all attempts to pass over it will be blocked till all of the threads have...
Logging
Logging Logging is a powerful way to help us develop a better understanding of the flow of our program while opening up ways to see different perspectives in the way we developed our code. Loggins is a method by which we can track different events that happen when our program is being executed. An event...
Basic Configurations in Logging
Basic Configurations The logging module offers a function called ‘basicConfig’ which allows us to configure how we log our code. This function has quite a few parameters which we can alter to modify the default behavior of our logs. We saw the debug(), info(), warning(), error(), and critical() function in the previous blog, but what...
Logging in a File
Logging to a File As we saw in the previous blog, Python allows us to store our log onto a file. Python offers two ways in which we can do this: Using the ‘filename’ parameter from the basicConfig() function. Using the FileHandler() function. Using basicConfig() As seen in the previous blog, the ‘filename’ parameter...
Logging Varriable Data
Variable Data When creating logs it will be useful if we had the option to use variables to make a more meaningful log record. While we can create variables that hold our string, we can also create logs that directly access a variable we require. import logging user_name = "Christopher" logging.warning("%s encountered a warning message",...
Logging Classes and Functions
Logging Classes & Functions So far, we have seen how we can create logs as well as how to write logs to a file. When creating logs we saw the term ‘logger’ when we discussed the name of the log, as well as creating a log using the FileHandler() function. Let’s dive deeper into what...
__name__ Variables
__name__ Variable Dunder In Python, we have what we call ‘dunder’ names, and it refers to a naming convention that uses double underscores at the start and end of the variable or function. The term ‘dunder’ means double underscores. The term ‘__name__’ is a special variable in Python which refers to the current script that...
Generators & Clousers
Generators Generators are functions and a function is deemed as a Generator function if it has one or more yield statements. Generators also provide us with a very simplistic way of creating iterator objects. They also do not store all of the values instead they generate one value at a time. In a practical setting,...
Decorator & Property
Decorators To better understand Decorators, consider a scenario of painting a house. If the house is already painted in one color let’s say white, we also have the option of adding another color of paint to a specific part of the house, without having to remove the entire paint of the house. Likewise, Decorators give...
Assert Statement
Assert Statement Python offers a keyword known as the ‘assert’ keyword and we use it to run conditional checks to handle different errors. If the condition is not satisfied an error is raised and the program halts. Assert also tells us where the error happened. This condition is known as the ‘Assertion Condition’ and the...
Garbage Collection
Garbage Collection Python uses Garbage Collection to free up memory that was given to the program after it has completed execution, and this also includes memory that was once given to a program at a certain time but is no longer in use by the program. Garbage collection helps us in memory management and also...
Shallow and Deep Copy
In Python, we can use the ‘=’ operator to copy one value of a variable to another. However, when we copy a value what happens underneath is that Python is simply creating another reference to the same variable. When one reference changes its internal value, the change is reflected in all references. Another important aspect...
datetime module
Python does not have a direct implementation to work with dates and time but we can use a built-in module called “datetime” to work with dates and time as objects. Consider an example: import datetime current_date_time = datetime.datetime.now() print(current_date_time) When we run this, we get: The output is displayed in the format of Year-Month-Day Hour:Minute:Second.Microsecond. Each...
Time module
Python offers a module called ‘time’ to create varying functions that are related to time as well as to achieve time-related tasks. Consider a function from the ‘time’ module which returns the number of seconds passed since ‘epoch’. Epoch is the time passed since January the first of 1970. import time # This prints time...