coderz.py

Keep Coding Keep Cheering!

Python Mathematical Operators

JOIN Clause
Mathematical Operators:

Mathematical Operators are used in mathematics to perform operations such as addition, subtraction, multiplication, and division.

Python has seven arithmetic operators:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus
  • Exponentiation
  • Floor division
Addition:

The addition operator in Python is +. It is used to combine two values.

Example:

v1 = 2
v2 = 30
  
# using the addition operator
res = v1 + v2
print(res)

Output:

32
Subtraction:

The subtraction operator in Python is -. It’s used to deduct the second value from the first.

Example:

v1 = 20
v2 = 3

# using the subtraction operator
res = v1 - v2
print(res)

Output:

17
Multiplication:

The multiplication operator in Python is *. It is used to compute the product of two values.

Example:

v1 = 20
v2 = 3

# using the multiplication operator
res = v1 * v2
print(res)

Output:

60
Division:

The division operator in Python is /. When the first operand is divided by the second, it yields the quotient.

Example:

v1 = 20
v2 = 3

# using the division operator
res = v1 / v2
print(res)

Output:

6.666666666666667
Modulus:

The modulus operator in Python is %. When the first operand is divided by the second, it returns the remainder.

Example:

v1 = 20
v2 = 3

# using the division operator
res = v1 % v2
print(res)

Output:

2
Exponentiation:

** is the Python exponentiation operator. It is used to raise the first operand to the power of the second operand.

Example:

v1 = 20
v2 = 3

# using the division operator
res = v1 ** v2
print(res)

Output:

8000
Floor division:

//  is used in Python to perform floor division. It is used to find the quotient’s floor when the first operand is divided by the second.

Example:

v1 = 22
v2 = 3

# using the division operator
res = v1 // v2
print(res)

Output:

7

Note: also read about Python Syntax Rules & Hello World Program

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Comment

Your email address will not be published. Required fields are marked *

Advertisement