Server Side Programming Articles

Page 128 of 2109

__new__ in Python

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 324 Views

The __new__ method in Python is a special method that controls object creation. Unlike __init__ which initializes an object, __new__ is responsible for actually creating and returning a new instance of a class before __init__ is called. Understanding __new__ The __new__ method is a static method that belongs to the class rather than instances. It's called automatically when creating objects and is particularly useful when you need to control the object creation process, implement design patterns like Singleton, or work with immutable classes. Basic Example − Input Validation Here's how to use __new__ to validate input ...

Read More

__init_subclass__ in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 27-Mar-2026 3K+ Views

In Python, the __init_subclass__ method is a special method that allows us to initialize or customize class creation, particularly for subclasses. Key Characteristics of __init_subclass__ Some of the key aspects of the __init_subclass__ method are as follows: Automatic Invocation: The __init_subclass__ method is automatically called during the creation of a subclass and no need to manually invoke this method. Customizable via Parameters: To pass additional ...

Read More

__init__ in Python

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 730 Views

The __init__ method is Python's constructor that automatically initializes objects when they are created. This special method allows us to set up the initial state and attributes of our custom classes, making objects ready to use immediately after creation. What is __init__? The __init__ method is a special "magic method" (also called "dunder method") that Python calls automatically when creating a new instance of a class. It serves as the constructor, allowing us to define how objects should be initialized with their starting values and state. Basic Syntax class ClassName: def ...

Read More

__getitem__ and __setitem__ in Python

Sarika Singh
Sarika Singh
Updated on 27-Mar-2026 5K+ Views

In Python, you can customize many operations like accessing or modifying elements of a list or dictionary using special methods. Two important methods that make your objects behave like lists or dictionaries are: __getitem__: called when you access an item using obj[key]. __setitem__: called when you assign a value using obj[key] = value. These are examples of dunder methods (short for "double underscore"). They are special methods in Python with names that begin and end with double underscores. When you use square bracket syntax on your object: obj[key] automatically triggers __getitem__ obj[key] = value ...

Read More

__future__ Module in Python

Sarika Singh
Sarika Singh
Updated on 27-Mar-2026 600 Views

The __future__ is a built-in Python module that allows you to import features from newer versions of Python into older versions. This enables forward compatibility and helps write code that works consistently across Python versions. What is the __future__ Module? The __future__ module is primarily used when migrating code from Python 2 to Python 3, or when you want to test new language features before they become default in future releases. It ensures your code behaves the same way across different Python versions. For example, in Python 2, dividing two integers returns an integer. By importing the ...

Read More

Full outer join in PySpark dataframe

Atharva Shah
Atharva Shah
Updated on 27-Mar-2026 2K+ Views

A Full Outer Join is an operation that combines the results of a left outer join and a right outer join. In PySpark, it is used to join two dataframes based on a specific condition where all the records from both dataframes are included in the output regardless of whether there is a match or not. This article will provide a detailed explanation of how to perform a full outer join in PySpark and provide a practical example to illustrate its implementation. Installation and Setup Before we can perform a full outer join in PySpark, we need to ...

Read More

Python program to print an Array

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 3K+ Views

In Python, an array (or list) is a collection of elements stored in a single variable with contiguous memory locations. Each element can be accessed using its index, which starts from 0 for the first element. Python lists are dynamic and can store homogeneous elements of the same datatype. The index represents the position of each element, ranging from 0 to n-1 for an array with n elements. Array Indexing Array indices are the position numbers used to access elements. The first element is at index 0, the second at index 1, and so on. For an ...

Read More

Python Program to Sort the 2D Array Across Columns

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 3K+ Views

When a two-dimensional array or a 2D array is declared, it is treated like a matrix with rows and columns. Sorting a 2D array across columns means sorting the elements within each column independently, either in ascending or descending order. Understanding Column-wise Sorting Consider this 2D array ? import numpy as np # Original 2D array arr = [[7, 9, 5, 7], [9, 5, 9, 4], [2, 7, 8, 6], [8, ...

Read More

Python Program to Remove Duplicate Elements From an Array

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 2K+ Views

An array is a collection of elements of the same data type, where each element is identified by an index value. It is the simplest data structure where each data element can be accessed directly using its index number. Arrays in Python Python does not have a specific data structure to represent arrays. Here, we can use a List as an array ? [6, 4, 1, 5, 9] 0 1 2 3 4 The indexing in Python starts from 0. In the above example, the integers 6, 4, 1, ...

Read More

Python Program to Remove All Occurrences of an Element in an Array/List

Nikhitha Chowdary Manne
Nikhitha Chowdary Manne
Updated on 27-Mar-2026 5K+ Views

An array is a collection of elements of homogeneous datatypes stored in contiguous memory locations. Python does not provide built-in arrays, but you can use lists or import the array module. Lists are more flexible as they can contain different data types. The task is to remove all occurrences of a specific element from a list, including duplicates. Let's explore different approaches to accomplish this ? Input Output Scenario Consider a list with repeated elements ? my_list = [1, 10, 20, 10, 21, 16, 18, 10, 22, 10, 8, 10] print("Original list:", my_list) print("Element 10 ...

Read More
Showing 1271–1280 of 21,090 articles
« Prev 1 126 127 128 129 130 2109 Next »
Advertisements