Arithmetic Operations in Python
Published by
sanya sanya
Overview
Arithmetic Operators are mathematical functions that carry out calculations on two operands. _Addition, subtraction, multiplication, division, modulus, exponentiation, _and floor division are examples of arithmetic operators.
Scope
- This article describes the many types of arithmetic operators that may be implemented in Python.
- The article also provides instances of its practical use.
Python Arithmetic Operators Overview
Assume you're shopping for groceries and there's a major discount going on. You're in line, and you immediately whip out your phone to figure out how much of a discount you're meant to get. In real life, calculators can save your life.
But what is the source of these calculations?
The solution is straightforward: Operators!
A calculator can execute basic mathematical operations for us, such as addition, subtraction, multiplication, and division. In the realm of coding, Arithmetic Operators in Python come to our aid and make our lives simpler!
In this post, we will learn all there is to know about Arithmetic Operators in Python and how to utilize them.
Let's start by learning about the various Arithmetic Operators in Python.
Python Arithmetic Operator Types
Arithmetic Operators in Python are primarily of the following types:
- Addition
- Subtraction
- Multiplication
- Division
- Floor Division
- Modulus
- Exponentiation
Let us now examine them more closely in order to better comprehend them.
1. Addition
Python's "+" operator represents addition. To add or sum two numbers, use this method.
Check out how it is implemented in the code:
https://images.codingblocks.com/data-science/add.png
Output:
The sum of 20 and 10 is: 30
2. Subtraction
The operator for subtraction in Python is "-". It takes away from the first value and adds the second one.
Let's look at how Python implements it.
Output:
The difference between 70 and 20 is: 50
3. Multiplication
Python's "*" arithmetic operator represents multiplication. We may determine the product of two numbers using this operator.
To help you understand, look at the following sample of code:
Output:
The product of 30 and 40 is: 1200
4. Division
In Python, the division operator is denoted by the symbol "/". By dividing the first operand by the second, we can determine the quotient.
Let's try coding it to see how it works.
Output:
The quotient of 60 and 40 is: 1.5
5. Modulus
In Python, the division operator is denoted by the symbol "%". This allows us to determine the remaining after dividing the first operand by the second.
Let’s see the following code implementation:
Output:
The remainder of 60 and 40 is: 20
6. Exponentiation
In Python, "**" stands for the exponentiation operator. It is applied to elevate the first operand's power to the second's power.
To further grasp this, let's look at the following sample of code:
Code:
Output:
The exponentiation of 3 and 4 is: 81
7. Floor Division
In Python, it is indicated by "//". When the first operand is divided by the second, we use it to determine the quotient's floor.
Code:
Output:
The floor division between 17 and 3 is: 5
Name | Operator | Example |
Addition | + | a+b |
Subtraction | - | a-b |
Multiplication | * | a*b |
Division | / | a/b |
Modulus | % | a%b |
Exponentiation | ** | a**b |
Floor Division | // | a//b |
Example to Implement Arithmetic Operators in Python
Let's examine a thorough illustration of arithmetic operators in Python code:
https://images.codingblocks.com/data-science/arithm_operators.png
Output:
Conclusion
The article has now come to a close. Let's review what we have studied this far: We learned what Python's arithmetic operators are.
- We discussed the many categories of Python arithmetic operators.
- We saw how their code was used.
You are now prepared to utilize Python's arithmetic operators independently. Coding is fun!
Library
WEB DEVELOPMENT
FAANG QUESTIONS
On this page
Overview
Scope
Python Arithmetic Operators Overview
Python Arithmetic Operator Types
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentiation
7. Floor Division
Example to Implement Arithmetic Operators in Python
Conclusion