Python Arithmetic Operators https://www.skillvertex.com/blog Thu, 11 Apr 2024 12:00:12 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.1 https://www.skillvertex.com/blog/wp-content/uploads/2024/01/favicon.png Python Arithmetic Operators https://www.skillvertex.com/blog 32 32 Python Arithmetic Operators https://www.skillvertex.com/blog/python-arithmetic-operators/ https://www.skillvertex.com/blog/python-arithmetic-operators/#respond Thu, 11 Apr 2024 12:00:12 +0000 https://www.skillvertex.com/blog/?p=6958 Read more]]>

Table of Contents

Python Arithmetic operators will work on mathematical operations such as addition, subtraction, multiplication, and division. Read this article to learn more about Python Arithmetic Operators.

What are Arithmetic Operators in Python?

Arithmetic operators are referred to as binary operators as they will perform on the two operands. Python will offer mixed arithmetic. Hence, these two operands will be of different types. In this kind of scenario, python can widen the narrower of the operands. Thus, the integer object is referred to as narrower than the float object and the float will be narrower than the complex object.

Therefore, the result of the arithmetic operation of int and float is a float. Similarly, the operation of an integer and complex object will give a complex object as the result.

What are the 7 Arithmetic Operators in Python?

The 7 arithmetic operators in Python are provided below

OperatorDescriptionSyntax
+The addition adds two operandsx + y
The subtraction will subtract two operandsx – y
*Multiplication can multiply two operandsx * y
/Division (float) can divide the first operand by the secondx / y
//Division (floor) will divide the first operand by the secondx // y
%The power Exponent will return the first raised to the power second.x % y
**The power Exponent will return the first raised to the power second.x ** y

Precedence of Arithmetic Operators in Python

Let us look into the Precedence and associativity of Python Arithmetic operators.

OperatorDescriptionAssociativity
**Exponentiation Operatorright-to-left
+, –
Addition and Subtraction operators

left-to-right
%, *, /, //
Modulos, Multiplication, Division, and Floor Division

left-to-righ

What are the Examples of Python Arithmetic Operators?

a.Addition Operator

+ is referred to as the addition operator and is used to add 2 values in Python Programming.

val1 = 2
val2 = 3
 
# using the addition operator
res = val1 + val2
print(res)

Output

5

b. Subtraction Operator

_ is denoted as the subtraction operator. It can subtract the second value from the first value.

val1 = 2
val2 = 3
 
# using the subtraction operator
res = val1 - val2
print(res)

Output

-1

c. Multiplication Operator

In Python Programming language, * is considered as the multiplication operator. It will find the product of 2 values.

val1 = 2
val2 = 3
 
# using the multiplication operator
res = val1 * val2
print(res)

Output

6

d. Division Operator

/ is referred to as the division operator in Python Programming language. It will find the quotient where the first operand will be divided by the second.

val1 = 3
val2 = 2
 
# using the division operator
res = val1 / val2
print(res)

Output

1.5

e. Modulus Operator

% is referred to as the modulus operator in Python Programming language. It will find the remainder where the first operand will be divided by the second.

val1 = 3
val2 = 2
 
# using the modulus operator
res = val1 % val2
print(res)

Output

1

f. Exponentiation Operator

In Python Programming language, ** is known as the exponentiation operator. It will raise the first operand to the power of the second.

val1 = 2
val2 = 3
 
# using the exponentiation operator
res = val1 ** val2
print(res)

Output

8

g. Floor Division Operator

// will do the floor division. It will help to find the floor of the quotient where the first operand can be divided by the second.

val1 = 3
val2 = 2
 
# using the floor division
res = val1 // val2
print(res)

Output

1

Conclusion

To conclude, beginners can improve their skill and knowledge by learning about the Arithmetic operators. The 7 arithmetic operators and their functions are also listed in this article.

Python Arithmetic Operators- FAQs

Q1. What is 3 dots in Python?

Ans. The Python ellipsis is considered a versatile object and has a placeholder, which helps in array slicing. It can improve type hiding, and simplify indexing, and multidimensional arrays.

Q2. What does == mean in Python?

Ans. = will represent the equality operator. Hence, the operator will return true only if the operands are equal.

Q3. What is the M flag in Python?

Ans. M Flag will allow us to run the

Hridhya Manoj

Hello, I’m Hridhya Manoj. I’m passionate about technology and its ever-evolving landscape. With a deep love for writing and a curious mind, I enjoy translating complex concepts into understandable, engaging content. Let’s explore the world of tech together

]]>
https://www.skillvertex.com/blog/python-arithmetic-operators/feed/ 0