Mathematical Operators are used in mathematics to perform operations such as addition, subtraction, multiplication, and division.
Python has seven arithmetic operators:
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
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
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
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
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
** 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
// 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
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
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…