Operators in Python
Prakash G Khaire
The Mandvi Education Society
Institute of Computer Studies
Operator
Types of operators in Python
Arithmetic Operators
Operator | Meaning | Example | Result |
+ | Addition Operator. Adds two Values. | a + b | 7 |
- | Subtraction Operator. Subtracts one value from another | a – b | 3 |
* | Multiplication Operator. Multiples values on either side of the operator | a * b | 10 |
/ | Division Operator. Divides left operand by the right operand. | a / b | 2.5 |
% | Modulus Operator. Gives reminder of division | a % b | 1 |
** | Exponent Operator. Calculates exponential power value. a ** b gives the value of a to the power of b | a ** b | 25 |
// | Integer division, also called floor division. Performs division and gives only integer quotient. | a // b | 2 |
| | | |
a = 5
b = 2
Assig | nm | x = 3 ent Operators y = 2 z = 5 | |
| | | |
Operator | Example | Meaning | Result |
= | z = x + y | Assignment operator. Stores right side value into left side variable. | z = 5 |
+= | z+=x | Addition assignment operator. Adds right operand to the left operand and stores the result into left operand. | z = 8 |
-= | z-=x | Subtraction assignment operator. subtracts right operand to the left operand and stores the result into left operand. | z = 2 |
*= | z*=x | Multiplication assignment operator. Multiplies right operand to the left operand and stores the result into left operand. | z = 15 |
/= | z/=y | Division assignment operator. Divides left operand with the right operand and stores the result into left operand. | z = 2.5 |
%= | z%=x | Modulus assignment operator. Divides left operand to the right operand and stores the result into left operand. | 2 |
**= | z**=y | Exponential assignment operator. Performs power value and then stores the result into left operands | 25 |
//= | z//=y | Floor division assignment operator. Performs floor division and then stores | 2 |
Assignment Operators
Arithmetic Operators
#To find the sum of two numbers
a = 10 # store 10 into variable a