Programming Articles

Page 576 of 2547

Base Overloading Methods in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 490 Views

Python provides special methods (also called magic methods or dunder methods) that you can override in your classes to customize their behavior. These methods allow your objects to work seamlessly with built-in functions and operators. Common Base Overloading Methods Sr.No. Method, Description & Sample Call 1 __init__(self [, args...])Constructor method called when creating an objectSample Call: obj = ClassName(args) 2 __del__(self)Destructor method called when object is garbage collectedSample Call: del obj 3 __repr__(self)Returns unambiguous string representation for developersSample Call: repr(obj) 4 __str__(self)Returns human-readable string representationSample ...

Read More

Destroying Objects (Garbage Collection) in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 1K+ Views

Python deletes unneeded objects (built-in types or class instances) automatically to free the memory space. The process by which Python periodically reclaims blocks of memory that no longer are in use is termed Garbage Collection. Python's garbage collector runs during program execution and is triggered when an object's reference count reaches zero. An object's reference count changes as the number of aliases that point to it changes. How Reference Counting Works An object's reference count increases when it is assigned a new name or placed in a container (list, tuple, or dictionary). The object's reference count decreases ...

Read More

Creating Instance Objects in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 38K+ Views

To create instances of a class, you call the class using class name and pass in whatever arguments its __init__ method accepts. Creating Instance Objects When you create an object, Python calls the class constructor (__init__ method) to initialize the new instance ? # This would create first object of Employee class emp1 = Employee("Zara", 2000) # This would create second object of Employee class emp2 = Employee("Manni", 5000) Accessing Object Attributes You access the object's attributes using the dot (.) operator with object. Class variables can be accessed using class name ? ...

Read More

Creating Classes in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

The class statement creates a new class definition. The name of the class immediately follows the keyword class followed by a colon as follows ? class ClassName: 'Optional class documentation string' class_suite The class has a documentation string, which can be accessed via ClassName.__doc__. The class_suite consists of all the component statements defining class members, data attributes and functions. Basic Class Structure A Python class contains attributes (data) and methods (functions). Here's the basic syntax ? ...

Read More

OOP Terminology in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 3K+ Views

Object-Oriented Programming (OOP) in Python uses specific terminology to describe its concepts. Understanding these terms is essential for working with classes, objects, and inheritance in Python. Core OOP Terms Class A user-defined blueprint for creating objects that defines attributes and methods. Think of it as a template that describes what data and behaviors objects will have ? class Car: wheels = 4 # Class variable def __init__(self, brand): self.brand = brand # Instance ...

Read More

Argument of an Exception in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 5K+ Views

An exception can have an argument, which is a value that provides additional information about the problem. The contents of the argument vary by exception. You capture an exception's argument by supplying a variable in the except clause as follows − Syntax try: # Your operations here pass except ExceptionType as argument: # You can access the exception argument here print(argument) If you write the code to handle a single exception, you can have a variable follow the name ...

Read More

Longest Palindromic Substring in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 11K+ Views

Finding the longest palindromic substring in a string is a classic dynamic programming problem. A palindrome reads the same forwards and backwards, like "BAB" or "RACECAR". We'll use a 2D table to track which substrings are palindromes. Algorithm Overview The approach uses dynamic programming with these steps ? Create a 2D boolean matrix where dp[i][j] represents if substring from index i to j is a palindrome Initialize single characters as palindromes (diagonal elements = True) Check substrings of increasing length, starting from length 2 For each substring, check if first and last characters match and the ...

Read More

Longest Substring Without Repeating Characters in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 8K+ Views

In Python, finding the longest substring without repeating characters is a classic string problem. We can solve this using different approaches: the Brute Force method which checks all possible substrings, and the more efficient Sliding Window technique using either a set or dictionary to track character positions. Common Methods The main approaches to find the longest substring without repeating characters are: Brute Force: Checks all possible substrings and verifies if they have unique characters. Sliding Window with Set: Uses a set to track characters in the current window and adjusts window boundaries dynamically. ...

Read More

Add Two Numbers in Python

gireesha Devara
gireesha Devara
Updated on 25-Mar-2026 3K+ Views

Adding two numbers in Python is one of the most basic tasks, where we need to combine their values to get a total. In this article, we will explore different ways to add two numbers in Python using various operators and built-in functions. Using Arithmetic Operator To add two numerical values in Python, we can use the addition operator, represented by the "+" symbol. It is one of the arithmetic operators in Python that performs the addition operation. Example Here is the basic example that adds the two numbers using the addition operator (+) − ...

Read More

Locating Modules in Python

gireesha Devara
gireesha Devara
Updated on 25-Mar-2026 2K+ Views

Locating modules in Python refers to the process of how Python finds and loads a module into our current program when we are trying to import it. Python's standard library comes with a large number of modules that we can use in our programs with the import statement. Module Search Process When you write an import statement like import mymodule, the Python interpreter searches for the module in the following sequence ? The current directory − Python first checks the directory of the current script. PYTHONPATH Environment Variable ...

Read More
Showing 5751–5760 of 25,466 articles
« Prev 1 574 575 576 577 578 2547 Next »
Advertisements