Server Side Programming Articles

Page 153 of 2109

How to detect whether a Python variable is a function?

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 6K+ Views

In this article, we will learn how to detect whether a Python variable is a function. Sometimes, it's essential to figure out whether a Python variable is a function, especially when working with large codebases or dynamically generated code. Methods to Check if a Variable is a Function The following are the methods to check whether a Python variable is a function − Using the built-in callable() function Using the isfunction() of the inspect module Using the type() function Using the built-in hasattr() function Using the isinstance() function Using the callable() Function The ...

Read More

How to create a dictionary of sets in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 3K+ Views

A dictionary of sets in Python stores sets as values for dictionary keys, automatically eliminating duplicates. This structure is useful for grouping unique items under different categories. Using Dictionary Literals The simplest way is to create a dictionary with sets as values using curly braces ? # Creating a dictionary with sets as values employee_data = { 'Employee_ID': {10, 11, 12, 14, 15}, 'Employee_Age': {25, 30, 40, 35, 28} } print("Dictionary of sets:") print(employee_data) Dictionary of sets: {'Employee_ID': {10, 11, 12, 14, 15}, 'Employee_Age': ...

Read More

How to capture SIGINT in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 1K+ Views

In this article, we will learn how to capture SIGINT in Python and what has to be done after capturing it. SIGINT is a signal sent when the user presses Ctrl+C (or Ctrl+F2 on Windows) to interrupt a running program. When the signal module receives signals, it performs specific actions. It can capture the user's keyboard interruption through SIGINT and allow you to define custom behavior instead of just terminating the program. Required Modules The following modules are needed for signal handling in Python − Signal Module The signal module provides mechanisms to handle asynchronous ...

Read More

How to Align Text Strings using Python?

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 36K+ Views

In this article, we will learn how to align text strings using Python. Python provides multiple ways to align text: f-strings with alignment specifiers and built-in string methods like ljust(), rjust(), and center(). Python's text alignment feature helps create well-formatted output. When data varies in length, proper alignment makes output more readable and professional-looking. You can specify left, right, or center alignment with a reserved width for consistent formatting. F-String Alignment Syntax F-strings use alignment symbols followed by width numbers ? − Right alignment ^ − Center alignment Left Alignment using F-strings ...

Read More

Find the maximum element of each row in a matrix using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 3K+ Views

In this article, we will learn Python programs to find the maximum element of each row in a matrix. We'll explore three efficient approaches to solve this common problem. Assume we have taken an NxN input matrix. We will now find the maximum element of each row in an input matrix using the below methods. Methods Used The following are the various methods to accomplish this task − Using Nested For Loops Using max() function Using map() and lambda functions Method 1: Using Nested For Loops Algorithm Following are the steps ...

Read More

Find the least frequent element in an array using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 1K+ Views

Finding the least frequent element in an array is a common programming problem. Python offers several approaches: sorting with linear traversal, hashing with dictionaries, and using the Counter class from the collections module. Methods Overview The following methods can accomplish this task − Using sort() function (Naive Approach) Using Hashing with Dictionary Using Counter() Function Method 1: Using sort() Function This approach first sorts the array, then traverses it linearly to count frequencies. The time complexity is O(n log n) due to sorting. Example The following program returns the least frequent ...

Read More

Decoding and encoding hexadecimal digitals using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 5K+ Views

In this article, we will learn how to decode and encode hexadecimal digits using Python. Python provides built-in modules like binascii and base64 that make hexadecimal conversion straightforward. What are Hexadecimal Digits? Hexadecimal is a base-16 number system that uses digits 0-9 and letters A-F to represent values. It's commonly used in programming to represent binary data in a more readable format. Method 1: Using binascii Module The binascii module provides functions to convert between binary and different ASCII-encoded binary representations. It's ideal when you need to encode or decode raw hex digit strings. Encoding ...

Read More

Decimal Equivalents of 1/2, 1/3, . . . ,1/10 in Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 2K+ Views

In this article, we will learn Python programs that calculate and display the decimal equivalents of fractions from 1/2, 1/3, 1/4, up to 1/10. We'll explore three different approaches to accomplish this task. Method 1: Basic Division for Single Fraction We can calculate the decimal equivalent of 1/2 using simple division. This demonstrates the basic concept before scaling to multiple fractions ? # Calculate decimal equivalent of 1/2 numerator = 1 denominator = 2 result = numerator / denominator print(f"1/{denominator} = {result}") 1/2 = 0.5 Method 2: Using range() Function ...

Read More

Check if the matrix is lower triangular using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 528 Views

In this article, we will learn a Python program to check if a matrix is lower triangular. A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. What is a Lower Triangular Matrix? A square matrix is called lower triangular if all entries above the main diagonal are zero. Elements on or below the main diagonal can be any value. Example of Lower Triangular Matrix 1 0 0 0 2 3 0 0 1 3 7 0 0 4 8 4 In ...

Read More

Calculating profit or loss using Python

Vikram Chiluka
Vikram Chiluka
Updated on 26-Mar-2026 7K+ Views

In this article, we will learn how to create Python programs to calculate profit or loss by comparing cost price and selling price. We'll explore two different approaches to solve this business problem. Understanding Cost Price, Selling Price, Profit and Loss Before diving into the code, let's understand the basic concepts ? The cost price (CP) is the amount paid to purchase a product. The selling price (SP) is the amount received when selling that product. Profit occurs when selling price is greater than cost price ? Profit = Selling Price - Cost Price ...

Read More
Showing 1521–1530 of 21,090 articles
« Prev 1 151 152 153 154 155 2109 Next »
Advertisements