Server Side Programming Articles

Page 624 of 2109

How to prevent loops going into infinite mode in Python?

Gireesha Devara
Gireesha Devara
Updated on 24-Mar-2026 3K+ Views

In Python, while loops can run infinitely if the loop condition never becomes False. To prevent infinite loops, you need to modify the condition variable inside the loop body or use control statements like break. Using a Counter Variable The most common approach is to use a counter that gets incremented in each iteration ? count = 0 while count < 5: print('Python!') count += 1 Python! Python! Python! Python! Python! Here, the count variable is incremented in each iteration, ensuring the condition ...

Read More

How to print a value for a given key for Python dictionary?

Jayashree
Jayashree
Updated on 24-Mar-2026 8K+ Views

Python dictionary is a collection of key-value pairs. There are several ways to print or access the value associated with a specific key. Using the get() Method The get() method returns the value for a given key. If the key doesn't exist, it returns None by default ? D1 = {'a': 11, 'b': 22, 'c': 33} print(D1.get('b')) print(D1.get('d')) # Key doesn't exist 22 None Using get() with Default Value You can provide a default value to return when the key is not found ? D1 = {'a': ...

Read More

How to convert float to integer in Python?

Gireesha Devara
Gireesha Devara
Updated on 24-Mar-2026 3K+ Views

In Python there are two main numeric data types: integers and floats. Integers are whole numbers without decimal points, while floats contain decimal values. Python provides several built-in methods to convert float values to integers ? Using the int() Function The int() function converts floating-point numbers to integers by truncating the decimal part. It does not round values − it simply removes everything after the decimal point. Basic Float to Integer Conversion Here's a simple example of converting a float to an integer ? num = 39.98 print('Data type of num:', type(num).__name__) ...

Read More

How to convert an integer to a character in Python?

Gireesha Devara
Gireesha Devara
Updated on 24-Mar-2026 39K+ Views

To convert an integer to a character in Python, we can use the chr() method. The chr() is a Python built−in function that returns a Unicode character corresponding to the given integer value. Syntax chr(number) Parameters number − An integer between 0 and 1, 114, 111 (0x110000 in hexadecimal). Return Value Returns a Unicode character corresponding to the integer argument. Raises ValueError if the integer is out of range (not in range(0x110000)). Raises TypeError for non−integer arguments. Basic Example Let's convert integer 100 to its corresponding Unicode character ? ...

Read More

nHow to print out the first character of each list in Python?

Shriansh Kumar
Shriansh Kumar
Updated on 24-Mar-2026 6K+ Views

A Python list is a built-in, mutable datatype that stores multiple items or elements, separated by commas, within square brackets [ ]. The index of a list in Python starts from 0 up to length-1. We can retrieve/access elements at a particular index as follows ? list_name[index] The given task is to write a Python program that prints the first character of each element in a list. But, before that, let's see some example scenarios: Scenario 1 For example, if our list contains string values, the output should be the first character of ...

Read More

What does \'is\' operator do in Python?

Disha Verma
Disha Verma
Updated on 24-Mar-2026 3K+ Views

The "is" operator in Python is an identity operator that checks whether two variables refer to the same object in memory. It returns True if both variables point to the same object, and False otherwise. Each object in Python's memory has a unique identification number assigned by the interpreter. The is operator compares these memory addresses using the id() function internally, making it different from the == operator which compares values. Syntax variable1 is variable2 The is operator returns True if both variables reference the same object in memory, False otherwise. Example with ...

Read More

What is "not in" operator in Python?

Pythonic
Pythonic
Updated on 24-Mar-2026 5K+ Views

In Python, the not in membership operator evaluates to True if it does not find a variable in the specified sequence and False otherwise. Syntax element not in sequence Example with Lists Let's check if elements are not present in a list ? a = 10 b = 4 numbers = [1, 2, 3, 4, 5] print(a not in numbers) print(b not in numbers) True False Since a (10) doesn't belong to numbers, a not in numbers returns True. However, b (4) can be found in ...

Read More

What is Python equivalent of the ! operator?

Gireesha Devara
Gireesha Devara
Updated on 24-Mar-2026 3K+ Views

In some languages like C / C++, the "!" symbol is used as a logical NOT operator. !x returns true if x is false, else returns false. The equivalent of this "!" operator in Python is the not keyword, which also returns True if the operand is false and vice versa. Basic Usage with Boolean Values Example with True Value In the following example, the variable operand_X holds a boolean value True. After applying the not operator, it returns False − operand_X = True print("Input: ", operand_X) result = not operand_X print('Result: ', result) ...

Read More

What does these operators mean (** , ^ , %, //) ?

Disha Verma
Disha Verma
Updated on 24-Mar-2026 729 Views

In Python, there are various types of operators used to perform specific functions, such as (**), (^), (%), and (//). The (**) operator represents exponentiation, (^) represents bitwise XOR, (%) represents the modulus operation, and (//) represents floor division. In this article, we will understand the workings of these operators. Exponentiation Operator (**) The exponentiation operator (**) is used to raise a number to a power. This operator works the same as the Python pow() method. In exponentiation, you need two numbers: the first is the base (the number you want to raise), and the second is the ...

Read More

What is the difference between = and == operators in Python?

Disha Verma
Disha Verma
Updated on 24-Mar-2026 2K+ Views

The symbols "=" and "==" look similar but have different meanings and usability in Python. The "=" symbol is the assignment operator, and the "==" symbol represents a comparison operator. In this article, we will understand the difference between these two and how to use them. The "=" Operator The "=" operator in Python is the assignment operator. It is used to assign a value to a variable. You put the variable on the left side and the value or expression on the right side. The value on the right is stored in the variable on the left. ...

Read More
Showing 6231–6240 of 21,090 articles
« Prev 1 622 623 624 625 626 2109 Next »
Advertisements