Python Operators

Python Operators


Operators are used to manipulating variables and values.

Example :- We use the + operator in the following example to add two values :

print(10 + 5)

Output :-

15

Python categorizes operators as follows :

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators
You can also search for these topics, python operators with examples, check the precedence of python operators, what is python operators, what does python operator do, how to use python operator, how to python operator works, how to create python operator, how to install python operator, Example for python operators.

Python Arithmetic Operators

With numerical values, arithmetic operators are employed for common mathematical activities :

Operator Name Example Result
+ Addition 5 + 10 Total of 5 and 10
- Subtraction 5 - 10 Minus of 5 and 10
* Multiplication 5 * 10 multiplying of 5 and 10
/ Division 5 / 10 Dividing of 5 and 10
% Modulus 5 % 10 balance of 5 and 10
** Exponentiation 5 ** 10 End of 5 and 10
// Floor division 5 // 10 floor division of 5 and 10
You can also search for these topics, python arithmetic operator, python program using arithmetic operator, python basic arithmetic operators, what are different arithmetic operator used in python, what are the arithmetic operator in python explain with example, how to use arithmetic operator in python, how many types of arithmetic operator are there in python.

Python Assignment Operators

To assign the values to the variables, assignment operators are also used :

Operator Example same as....
= a = 5 a = 5
+= a += 3 a = a + 3
-= a -= 3 a = a - 3
*= a *= 3 a = a * 3
/= a /= 3 a = a / 3
%= a %= 3 a = a % 3
//= a //= 3 a = a // 3
**= a **= 3 a = a ** 3
&= a &= 3 a = a & 3
|= a |= 3 a = a | 3
^= a ^= 3 a = a ^ 3
>>= a >>= 3 a = a >> 3
<<= a <<= 3 a = a << 3
You can also search for these topics, python assignment operators example, how to copy assignment operators in python, what are assignment operators in python, what are the assignment operators that can be used in python, examine the assignment operator default value, python assign to operator error, get the assignment operators using python, Example for python assignment operators.

Python Comparison Operators

Two values are used to make comparisons operators of comparison :

Operator Name Example
== Equal a == b
!= Not equal a != b
> Greater than a > b
< Less than a < b
>= Greater than or equal to a >= b
<= Less than or equal to a <= b


You can also search for these topics, python comparison operators example, what are different comparison operator in python, what are the six comparison operator in python, how to use comparison operator in python, select the python comparison operator, python comparison operator list.

Python Logical Operators

To merge conditional formatting, logical operators are employed :

Operator Description Example
and Returns True if both statements are true x < 5 and x < 10
or Returns True if one of the statements is true x < 5 or x < 4
not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
You can also search for these topics, python logical operator exercises, define the symbols of logical operators in python, true and false using logical operator using python, priority for python logical operator, what are the python logical operators, what is the use of logical operator in python, Example for Python Logical Operators.

Python Identity Operators

Used to comparing objects are the identity operators, not if they are equal, but if they are the same object, with the same memory location :

Operator Description Example
is Returns True if both variables are the same object a is b
is not Returns True if both variables are not the same object a is not b


You can also search for these topics, python identity operators are used for, python membership and identity operator, example for python identity operators, what is identity operator inn python, which of the following is the identity operators in python, difference between equality and identity operators in python.

Python Membership Operators

Membership operators shall be used to test whether an object shows a sequence :

Operator Description Example
in Returns True if a sequence with the specified value is present in the object a in b
not in Returns True if a sequence with the specified value is not present in the object a not in b
You can also search for these topics, python membership and identity operator, what is the use of membership operator in python, name the two memebership operator n python, explain the membership operator used in python, which of the following are membership operators in python, example for membership operators in python.

Python Bitwise Operators

Bitwise are used to compare (binary) numbers by operators :

Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
You can also search for these topics, python bitwise operator questions, bitwise operator bin python, bitwise operators python code, differenciate the bitwise operators in python.