Posts

Data Structures - Part 2

Data Structures - Part 2 Data Structures (Abstract Data Types) - Part 2 (Linked List) Refer this article for Part 1 (Array) of the series. 2. Linked List A linked list is a linear data structure where elements are stored in nodes. Each node consists of two parts: data (which holds the value) and a reference (or pointer) to the next node in the sequence. In contrast to arrays, elements (nodes) in a linked list are not stored in contiguous memory locations but instead are connected via pointers. Unlike arrays, linked lists are dynamic and can grow or shrink in size as needed. They do not have a built-in length property, though such feature can be implemented in custom classes. To determine the number of elements in a linked list, we typically need to traverse the entire list and count the nodes. This structure which involves updating pointers, makes insertions and deletions faster since it avoids the need to shift elements, in contrast to arrays. However, lin...

Data Structures - Part 1

Data Structures - Part 1 Data Structures (Abstract Data Types) - Part 1 (Array) Data structures are specific methods of organizing and storing collections of data in a way that enables efficient access and manipulation. In a previous article , we discussed python specific data structures (built-in data types: list, tuple, set & dictionary) . In this series of articles, we will explore common abstract data types (ADTs) that are language-agnostic. These ADTs can be classified into two categories: linear and non- linear. Linear data structures; Array , Linked List , Stack , Queue Non-linear data structures; Tree , Hash Map , Graph 1. Array Arrays are one of the most fundamental data structures, designed to store collections of data (elements) of the same data type . These elements are stored in contiguous memory locations, allowing access to each element using its index. Arrays are prone to an exception if accessed with an index that exceeds the array’s boun...

OOP with Python - Part 2

OOP with Python - Part 2 OOP with Python - Part 2 We covered the basics of Object-Oriented Programming (OOP) , including Classes and Objects, Encapsulation, and Inheritance in OOP with Python - Part 1 . In this second part, we will discuss the remaining two key principles of OOP; Abstraction and Polymorphism . Abstraction Abstraction is the concept of hiding the complex implementation details of a system and exposing essential features of an object. This allows us to focus on what an object does but not how it is done. This can reduce programming complexity and enhance code maintainability. In Python, abstraction can be achieved using abstract classes and methods provided by the abc module. An abstract class is a class that cannot be instantiated and typically contains one or more abstract methods. An abstract method is a method that is declared but contains no implementation. Subclasses of the abstract class must provide implementations for all abstract m...

OOP with Python - Part 1

OOP with Python - Part 1 OOP with Python - Part 1 OOP ( Object Oriented Programming ) is a programming paradigm (a design style or an approach with its related design principles and techniques) which considers objects as the primary building block of a software program. In our previous articles, we were following a procedural approach where we were writing our code in a sequential manner. As compared to the procedural approach, OOP provides benefits like modularity, ease of maintenance, flexibility, scalability and reusability which makes it ideal for large scale real world projects. Python, being a general purpose language, supports both procedural and OOP paradigms. So, in this article let’s talk about the basics of OOP and how to implement them in Python. Class & Object An object is a real world entity with properties (aka attributes or data or members) and behaviors (aka methods or functions). For instance, a cat is an object. It has a name, color ...

Debugging with Python - Part 3

Debugging with Python - Part 3 Debugging with Python - Part 3 Refer this article for Debugging with Python - Part 1. Refer this article for Debugging with Python - Part 2 (Debugging techniques - Part 1). Debugging techniques - Part 2 5. Exception Handling : Exception handling is the process used to prevent runtime errors occurring at the execution time, so that these errors wouldn’t cause our program to crash. In python, we can use try and except blocks to help us handle runtime errors and print out useful error messages. Let’s modify the simple calculator program we used in our type casting article to handle exceptions of user input and division by zero. while True : try : number1 = float ( input ( "Enter 1st number: " ) ) number2 = float ( input ( "Enter 2nd number: " ) ) result = round ( number1 / number2 , 2 ) except ValueError : print ( "Incorrect value, Enter a...