Articles on Trending Technologies

Technical articles with clear explanations and examples

degrees() and radians() in Python

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

The measurements of angles in mathematics are done using two units: degrees and radians. They are frequently used in math calculations involving angles and need conversion from one value to another. In Python, we can achieve these conversions using built-in functions from the math module. degrees() Function This function takes a radian value as parameter and returns the equivalent value in degrees. The return type is a float value. Syntax math.degrees(x) Where x is the angle in radians. Example import math # Converting radians to degrees print("1 radian in ...

Read More

chr () in Python

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

The chr() function in Python returns a string representing a character whose Unicode code point is the integer supplied as parameter. For example, chr(65) returns the string 'A', while chr(126) returns the string '~'. Syntax The syntax of the chr() function is as follows ? chr(n) Where n is an integer value representing the Unicode code point. Basic Example The below program shows how chr() is used. We supply various integer values as parameters and get back the respective characters ? # Printing the strings from chr() function print(chr(84), chr(85), ...

Read More

Generating random number list in Python

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

There is a need to generate random numbers when studying a model or behavior of a program for different range of values. Python can generate such random numbers by using the random module. In the below examples we will first see how to generate a single random number and then extend it to generate a list of random numbers. Generating a Single Random Number The random() method in random module generates a float number between 0 and 1. Example import random n = random.random() print(n) Output Running the above code gives ...

Read More

gcd() function Python

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

The Greatest Common Divisor (GCD) is the largest positive integer that divides both numbers without leaving a remainder. Python provides the gcd() function in the math module to calculate this efficiently. Syntax math.gcd(x, y) Parameters: x − First integer y − Second integer Return Value: Returns the greatest common divisor as an integer. Example Let's find the GCD of different pairs of numbers ? import math print("GCD of 75 and 30 is", math.gcd(75, 30)) print("GCD of 48 and 18 is", math.gcd(48, 18)) print("GCD of 17 and 13 ...

Read More

frozenset() in Python

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

The frozenset() function in Python creates an immutable set from an iterable. Unlike regular sets, frozensets cannot be modified after creation, making them useful when you need a collection that should remain unchanged. Syntax frozenset(iterable) Parameters: iterable (optional): Any iterable object like list, tuple, string, or set. If no argument is provided, returns an empty frozenset. Creating a Frozenset from a List Here's how to convert a mutable list to an immutable frozenset ? # Create a list days = ["Mon", "Tue", "Wed", "Thu"] print("Original list:", days) # ...

Read More

floor() and ceil() function Python

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

Python's math module provides two useful functions for rounding decimal numbers to integers: floor() and ceil(). These functions help convert fractional numbers to their nearest integer values in different directions. floor() Function The floor() function returns the largest integer that is less than or equal to the given number. For positive numbers, it rounds down; for negative numbers, it rounds away from zero. Syntax math.floor(x) Where x is a numeric value Example of floor() Let's see how floor() works with different types of numeric values ? import math x, ...

Read More

Finally keyword in Python

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

The finally keyword in Python defines a block of code that executes regardless of whether an exception occurs or not. This makes it useful for cleanup operations like closing files, database connections, or releasing resources. Syntax try: # Main Python code except ExceptionType: # Optional block to handle specific exceptions finally: # Code that always executes Example with Exception Handling Here's an example where a NameError occurs when trying to print an undefined variable ? try: ...

Read More

divmod() in Python and its application

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

The divmod() function is part of Python's standard library which takes two numbers as parameters and returns the quotient and remainder of their division as a tuple. It is useful in many mathematical applications like checking for divisibility of numbers and establishing if a number is prime or not. Syntax divmod(a, b) Parameters: a − The dividend (number to be divided) b − The divisor (number that divides a) Both a and b can be integers or floats Return Value: Returns a tuple (quotient, remainder) Examples with Integers and Floats ...

Read More

casefold() string in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 206 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
Showing 1–10 of 61,299 articles
« Prev 1 2 3 4 5 6130 Next »
Advertisements