Python
Operators
Python offers a rich set of operators for various
operations. These operators enable powerful and flexible
code.
by ronak agrawal
Arithmetic Operators
1 Addition (+) 2 Subtraction (-)
Adds two operands. Subtracts the second operand from the first.
3 Multiplication (*) 4 Division (/)
Multiplies two operands. Divides the first operand by the second.
Comparison Operators
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Assignment Operators
Basic Assignment (=)
Assigns a value to a variable.
Addition Assignment (+=)
Adds and assigns.
Subtraction Assignment (-=)
Subtracts and assigns.
Multiplication Assignment (*=)
Multiplies and assigns.
Logical Operators
and or not
True if both operands are true. True if at least one operand Inverts the truth value of
is true. its operand.
Bitwise Operators
& (AND) | (OR)
Bitwise AND operation. Bitwise OR operation.
^ (XOR) ~ (NOT)
Bitwise XOR operation. Bitwise NOT operation.
Membership and Identity
Operators
1 in
Checks if a value is present in a sequence.
2 not in
Checks if a value is not present.
3 is
Checks if two variables refer to the same object.
4 is not
Checks if two variables do not refer to the same object.