Programming Articles

Page 893 of 2547

casefold() string in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 221 Views

The casefold() method in Python converts a string to lowercase, making it ideal for case-insensitive string comparisons. Unlike lower(), casefold() handles special Unicode characters more aggressively, making it the preferred choice for string matching. Syntax string.casefold() This method takes no parameters and returns a new string with all characters converted to lowercase. Basic Usage Here's how to convert a string to lowercase using casefold() − string = "BestTutorials" # print lowercase string print("Lowercase string:", string.casefold()) Lowercase string: besttutorials Case-Insensitive String Comparison You can compare two ...

Read More

Capitalize first letter of a column in Pandas dataframe

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

A Pandas DataFrame is similar to a table with rows and columns. Sometimes we need to capitalize the first letter of strings in a specific column, which can be achieved using the str.capitalize() method. Creating a DataFrame Let's start by creating a DataFrame with columns for days and subjects ? import pandas as pd # Create a DataFrame df = pd.DataFrame({ 'Day': ['mon', 'tue', 'wed', 'thu', 'fri'], 'Subject': ['math', 'english', 'science', 'music', 'games'] }) print(df) Day ...

Read More

XMLRPC server and client modules in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 4K+ Views

XML-RPC (XML Remote Procedure Call) is a protocol that allows programs to make function calls over HTTP using XML for encoding. Python's xmlrpc.server and xmlrpc.client modules make it easy to create cross-platform, language-independent servers and clients. Creating an XML-RPC Server We use SimpleXMLRPCServer to create a server instance and register functions that clients can call remotely. The server listens for incoming requests and executes the appropriate functions ? Example from xmlrpc.server import SimpleXMLRPCServer from xmlrpc.server import SimpleXMLRPCRequestHandler class RequestHandler(SimpleXMLRPCRequestHandler): rpc_paths = ('/RPC2', ) with SimpleXMLRPCServer(('localhost', 9000), ...

Read More

Python Code Objects

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Code objects are a low-level detail of the CPython implementation. Each one represents a chunk of executable code that hasn't yet been bound into a function. Though code objects represent some piece of executable code, they are not, by themselves, directly callable. To execute a code object, you must use the exec() function. Code objects are created using the compile() function and contain various attributes that provide information about the compiled code, such as bytecode, variable names, and filename. Creating a Code Object Use the compile() function to create a code object from a string of Python ...

Read More

Python a += b is not always a = a + b

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 215 Views

In Python, the expressions a += b and a = a + b are not always equivalent, especially when dealing with mutable objects like lists. The key difference lies in how Python handles these operations internally. Understanding the Difference For immutable types like integers and strings, both expressions produce the same result. However, for mutable types like lists, the behavior differs significantly: a = a + b creates a new object a += b modifies the existing object in-place (when possible) Case of a = a + b When using a = a ...

Read More

Python - Create Test DataSets using Sklearn

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 449 Views

The Sklearn Python library provides sample datasets which can be used to create various graph plots. The usefulness of these datasets is in creating sample graphs and charts, predicting graph behavior as values change, and experimenting with parameters like colors and axes before using actual datasets. Using make_blobs The make_blobs function generates isotropic Gaussian blobs for clustering. This is useful for testing clustering algorithms and creating scatter plots with distinct groups of data points. Example In the below example we use the sklearn library along with matplotlib to create a scatter plot with a specific style. ...

Read More

Find maximum length sub-list in a nested list in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

Finding the maximum length sub-list in a nested list is a common task when working with data structures in Python. This article explores different approaches to identify the longest sub-list and return both the sub-list and its length. Using lambda and max() The most efficient approach combines lambda with the max() function. The max() function uses a key parameter to determine which sub-list has the maximum length ? Example def longest(nested_list): longest_list = max(nested_list, key=lambda i: len(i)) max_length = max(map(len, nested_list)) return longest_list, ...

Read More

Python Generate QR Code using pyqrcode module?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 585 Views

A QR code consists of black squares arranged in a square grid on a white background, which can be read by an imaging device such as a camera. It is widely used for commercial tracking applications, payment systems, and website login authentication. The pyqrcode module is used to generate QR codes in Python. There are four standardized encoding modes: numeric, alphanumeric, byte/binary, and kanji to store data efficiently. Installation First, install the pyqrcode module using pip ? pip install pyqrcode Basic QR Code Generation We use the pyqrcode.create() function to generate a QR ...

Read More

Python Front and rear range deletion in a list?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 248 Views

Sometimes we need to remove elements from both the beginning and end of a list simultaneously. Python provides several approaches to delete elements from both the front and rear of a list efficiently. Using List Slicing This approach creates a new list by slicing elements from both ends. The original list remains unchanged ? days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Given list print("Given list:", days) # Number of elements to delete from front and rear v = 2 # Create new list excluding v elements from each end new_list ...

Read More

Python file parameter in print()?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

The print() function in Python can write text to different destinations using the file parameter. By default, print() outputs to the console, but you can redirect it to files or other output streams. Syntax print(*values, file=file_object, sep=' ', end='', flush=False) The file parameter accepts any object with a write() method, such as file objects, sys.stdout, or sys.stderr. Printing to a File You can write directly to a file by opening it in write mode and passing the file object to the file parameter ? # Open file in write mode with ...

Read More
Showing 8921–8930 of 25,466 articles
« Prev 1 891 892 893 894 895 2547 Next »
Advertisements