![]() |
VOOZH | about |
In Python programming, Operators in general are used to perform operations on values and variables.
Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication and division.
In Python, the division operator (/) returns a floating-point result, while floor division (//) returns an integer result.
Addition: 19 Subtraction: 11 Multiplication: 60 Division: 3.75 Floor Division: 3 Modulus: 3 Exponentiation: 50625
Note: Refer to Differences between / and //.
Comparison(or Relational) operators compares values. It either returns True or False according to the condition.
False True False True False True
Logical operators perform Logical AND, Logical OR and Logical NOT operations. It is used to combine conditional statements.
The precedence of Logical Operators in Python is as follows:
False True False
Bitwise operators act on bits and perform bit-by-bit operations. These are used to operate on binary numbers.
Bitwise Operators in Python are as follows:
0 14 -11 14 2 40
Assignment operators are used to assign values to the variables. This operator is used to assign the value of the right side of the expression to the left side operand. Example:
10 20 10 100 102400
"is" and "is not" are the identity operators and both are used to check if two values are located on the same part of the memory. Two variables that are equal do not imply that they are identical.
is True if the operands are identical
is not True if the operands are not identical
True True
"in" and "not in" are the membership operators that are used to test whether a value or variable is in a sequence.
in True if value is found in the sequence
not in True if value is not found in the sequence
x is NOT present in given list y is present in given list
Ternary operators also known as conditional expressions are operators that evaluate something based on a condition being true or false. It was added to Python in version 2.5.
It simply allows testing a condition in a single line replacing the multiline if-else, making the code compact.
Syntax : [on_true] if [expression] else [on_false]
10
Operator precedence and associativity determine the priorities of the operator.
This is used in an expression with more than one operator with different precedence to determine which operation to perform first.
610 Hello! Welcome.
If an expression contains two or more operators with the same precedence then Operator Associativity is used to determine. It can either be Left to Right or from Right to Left.
100.0 6 0 512