Found 10416 Articles for Python

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

Disha Verma
Updated on 18-Apr-2025 14:15:37

1K+ 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 ... Read More

What is different in OR and AND operators in Python?

Disha Verma
Updated on 18-Apr-2025 14:48:45

6K+ Views

The OR and AND operators are the most commonly used logical operators. The logical operators are used to perform decision-making operations. These combine multiple conditions and make a decision based on them. In this article, we will understand what OR and AND operators are in Python and how they differ, along with examples for better understanding. AND Operator in Python The logical AND operator in Python needs two operands. It returns true if both operands are true,  and it returns false if either of the operands is false. This operator is mostly used in situations where you ... Read More

What is different in | and OR operators in Python?

Disha Verma
Updated on 21-Apr-2025 16:33:43

1K+ Views

The OR and (|) are logical operators in Python. The difference between these two is that OR is a Logical OR operator, and | is a Bitwise OR Operator. Both operators are used to perform different operations. In this article, we will explore the behavior of these operators and their differences. OR Operator in Python The OR operator in Python returns true if one of the operands is true and false if both operands are false. This operator needs two values or operands to perform the operation and return the result. OR Operator Example The following ... Read More

What is different in & and AND operators in Python?

Disha Verma
Updated on 18-Apr-2025 15:05:04

475 Views

The AND and & are logical operators in Python that are used to perform different operations. The AND is a logical AND operator, and the ampersand (&) is a bitwise operator. In this article, we will explore the behavior of these operators and their differences. AND Operator in Python The logical AND operator in Python needs two operands. This operator returns true if both operands are true and false if either operand is false. This operator is mostly used in situations where you want to make sure that two things are true at the same time. Example of the AND ... Read More

What are boolean operators in Python?

Disha Verma
Updated on 18-Apr-2025 15:12:10

7K+ Views

The Boolean operators in Python return two values, either true or false. These operators are mostly used in conditional statements, loops, and logical expressions. Python has a built-in Boolean datatype that returns Boolean values based on comparisons or logical evaluations between operands. Boolean Operators in Python There are three main Boolean operators in Python: OR, AND, and NOT. These operators return Boolean values based on the operands. OR Operator in Python The OR operator in Python returns true if one of the operands is true and false if both operands are false. This operator ... Read More

What is modulo % operator in Python?

Disha Verma
Updated on 18-Apr-2025 15:21:04

571 Views

The modulo operator is denoted by the "%" symbol in Python. It can also be called the remainder operator because it is used to return the remainder of the division of two numeric operands. Using this operator, we can solve problems ranging from simple to complex. Syntax of Python Modulo Operator The modulo operator in Python works the same as the remainder of dividing the two numeric operands. Following is the syntax of the modulo operator - Result = a % b Where a and b are the operands, % represents the modulo operator, and ... Read More

What is tilde (~) operator in Python?

Akshitha Mote
Updated on 15-Apr-2025 17:47:07

7K+ Views

In Python, the bitwise operator ~ (pronounced as tilde) is a complement operator. It takes one bit operand and returns its complement. If the operand is 1, it returns 0, and if it is 0, it returns 1. For example, consider the 4-bit binary number (1100)2. By performing the tilde operation, each bit is flipped and results in (0011)2. Tilde Operation on Decimal Numbers When we perform a tilde operation on decimal numbers, the following steps are involved: Convert the decimal number to binary, including the sign. If the number is positive, place 0 in ... Read More

What is operation of <> in Python?

Niharika Aitam
Updated on 28-Feb-2025 18:42:23

107 Views

Understanding the Operator in Python The is one of the operators available in Python. The present version that we are using is Python 3. The previous version was Python 2. Some of the operators in Python 2 don't support in Python 3. is used in Python 2, which is not supported in Python. The operator != is used in Python 3. The functionality of the or != is to represent not equal to. The output of these operators is in the format of Boolean values True or False. Syntax The following is the syntax for using ... Read More

What is behavior of ++ and -- operators in Python?

Akshitha Mote
Updated on 15-Apr-2025 14:28:21

266 Views

In C/C++, Java, etc., ++ and -- operators are defined as increment and decrement operators. In Python, they are not defined as operators. Increment and Decrement Operators in Python In Python, objects are stored in memory. Variables are just labels. Numeric objects are immutable. Hence, they can't be incremented or decremented. However, prefix ++ or -- doesn't give an error but doesn't perform either. As Prefix  In the following example, when have used prefix increment which does not raise an error - x=5 print(++x) print(--x) Following is the output of the above code - 5 5 As Postfix In ... Read More

Explain function of % operator in Python.

Akshitha Mote
Updated on 18-Apr-2025 19:16:17

576 Views

The % symbol in Python is defined as the modulo operator. It can also called as remainder operator. It returns the remainder of the division of two numeric operands (except complex numbers). The Python modulo % operator is a part of arithmetic operations like addition (+), subtraction (-), multiplication (*), division (/), exponential (**), and floor division (//). The following is the basic syntax for the % modulo operator - x % y Modulo Operation on Integers When we perform a modulo operation on two integers, the result is the remainder of the division, ... Read More

Advertisements