Programming Articles

Page 132 of 2547

HandCalcs Module Python

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

HandCalcs is a Python library that automatically generates LaTeX-formatted mathematical equations from Python calculations. It creates beautiful, hand-written-style mathematical documentation directly from your Python code, making it essential for technical reports and scientific documentation. Installation Install HandCalcs using pip ? pip install handcalcs Basic Usage HandCalcs works primarily in Jupyter notebooks using the %%render magic command. Import the library and use the decorator to render calculations ? import handcalcs.render Example 1: Basic Arithmetic This example demonstrates simple numerical calculations with automatic LaTeX rendering ? %%render a ...

Read More

{{ form.as_p }} – Render Django Forms as Paragraph

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 3K+ Views

Django's form system provides several built-in methods to render forms in templates. The {{ form.as_p }} method is one of the most commonly used approaches, rendering each form field wrapped in a (paragraph) element for clean, organized display. Understanding Django Forms Before exploring {{ form.as_p }}, let's understand how Django forms work. Django provides a Form class to define form structure and validation rules ? from django import forms class ContactForm(forms.Form): name = forms.CharField(max_length=100) email = forms.EmailField() message = forms.CharField(widget=forms.Textarea) ...

Read More

__subclasscheck__ and __subclasshook__ in Python

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 1K+ Views

Python provides powerful mechanisms for customizing inheritance behavior through two special methods: __subclasscheck__ and __subclasshook__. These methods allow you to define custom criteria for determining subclass relationships beyond traditional inheritance. Understanding __subclasscheck__ and __subclasshook__ By default, Python's issubclass() function checks the inheritance tree to determine class relationships. However, you can override this behavior using these special methods: __subclasscheck__(cls, subclass) − Called by issubclass() to test if a class is a subclass. Can be overridden to provide custom inheritance logic. __subclasshook__(cls, subclass) − Defined in abstract base classes (ABCs) to customize subclass checks. Called by the default ...

Read More

__new__ in Python

Tushar Sharma
Tushar Sharma
Updated on 27-Mar-2026 327 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 739 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 608 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

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
Showing 1311–1320 of 25,466 articles
« Prev 1 130 131 132 133 134 2547 Next »
Advertisements