Server Side Programming Articles

Page 572 of 2109

Regular Expression Modifiers in Python

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

Regular expression modifiers (also called flags) are optional parameters that control how pattern matching behaves. You can combine multiple modifiers using the bitwise OR operator (|) to customize the search behavior. Common Regular Expression Modifiers Modifier Name Description re.I IGNORECASE Performs case-insensitive matching re.M MULTILINE Makes ^ and $ match start/end of each line re.S DOTALL Makes dot (.) match any character including newline re.X VERBOSE Ignores whitespace and allows comments in patterns re.L LOCALE Uses locale-aware matching (deprecated) re.U UNICODE ...

Read More

Data Hiding in Python

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 7K+ Views

Data hiding is also known as data encapsulation and it is the process of hiding the implementation of specific parts of the application from the user. Data hiding combines members of class thereby restricting direct access to the members of the class. Data hiding plays a major role in making an application secure and more robust. Data Hiding in Python Data hiding in Python is a technique of preventing methods and variables of a class from being accessed directly outside of the class in which the methods and variables are initialized. Data hiding of essential member functions ...

Read More

Overloading Operators in Python

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

In Python, you can customize how operators work with your custom classes through operator overloading. This is achieved by defining special methods (also called magic methods) in your class that correspond to specific operators. Suppose you have created a Vector class to represent two-dimensional vectors, what happens when you use the plus operator to add them? Most likely Python will yell at you. You could, however, define the __add__ method in your class to perform vector addition and then the plus operator would behave as per expectation ? Example class Vector: ...

Read More

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
Showing 5711–5720 of 21,090 articles
« Prev 1 570 571 572 573 574 2109 Next »
Advertisements