Python - Arithmetic operators



Arithmetic operators are used for performing mathematical operations like addition, subtraction, multiplication, etc.
Arithmetic operators in Python
OperatorMeaningExample
+Add two operands or unary plusx + y
+2
-Subtract right operand from the left or unary minusx - y
-2
*Multiply two operandsx * y
/Divide left operand by the right one (always results into float)x / y
%Modulus - the remainder of the division of left operand by the rightx % y (remainder of x/y)
//Floor division - division that results into the whole number adjusted to the left in the number linex // y
**Exponent - left operand raised to the power of rightx**y (x to the power y)

Example #1: Arithmetic operators in Python

  1. x = 15
  2. y = 4
  3. # Output: x + y = 19
  4. print('x + y =',x+y)
  5. # Output: x - y = 11
  6. print('x - y =',x-y)
  7. # Output: x * y = 60
  8. print('x * y =',x*y)
  9. # Output: x / y = 3.75
  10. print('x / y =',x/y)
  11. # Output: x // y = 3
  12. print('x // y =',x//y)
  13. # Output: x ** y = 50625
  14. print('x ** y =',x**y)
When you run the program, the output will be:
x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625







Comments

Popular posts from this blog

Python - Argument Passing

Python - How to Escape special characters in String