Python Arithmetic Operators

Arithmetic Operators in Python.

For performing mathematical operations such as addition , subtraction , multiplication, division, etc., arithmetic operators are used.
In between operands, arithmetic operators can be set. Elements on which operation is supposed to be performed are called operand in mathematical operations, and the operator used between two operands performs the type of operation.
python-arithmetic-operators

Arithmetic Operators in Python

Arithmetic Operators are used to perform mathematical operations on numeric values, such as integers and floating-point numbers. All Arithmetic Operators in python are discussed below  in detail with their syntax and proper example:

1. Addition(+)

It adds two operands and returns the sum.

Syntax

Operand1 + Operand2 = Result

Example

>>> a=10
>>> b=20
>>> a+b
30
>>> a+1
11
>>> "PREP"+"INSTA"
'PREPINSTA'
>>> 2+3
5

2. Subtraction(-)

It subtracts one operand from the other and returns there difference either positive or negative depending on the actual values of operands.

Syntax

Operand1 - Operand2 = Result

Example

>>> a=10
>>> b=20
>>> b-a
10
>>> a-1
9
>>> 20-3
17

3. Multiplication(*)

It multiplies two operands and returns the product of both the operands.

Syntax

Operand1 * Operand2 = Result

Example

>>> a=10
>>> b=20
>>> a*b
200
>>> a*9
90
>>> 20*3
60
>>> "Prep"*3 
'PrepPrepPrep'

4.Division ( / )

It divides one operand by another and returns the quotient in floating point values.

Syntax

Operand1 / Operand2 = Result

Example

>>> a=10
>>> b=20
>>> b/a
2.0
>>> a/2
5.0
>>> 20/3
6.666666666666667

5.Modulus ( % )

It divides one operand by another and returns the remainder if there is any else it returns 0.

Syntax

Operand1 % Operand2 = Result

Example

>>> a=10
>>> b=25
>>> b%a
5
>>> a%3
1
>>> 20%3
2

6.Exponential ( ** )

The exponential operator (**) is used to calculate power. e.g., 23 (2 raised to power 3).

Syntax

Operand1 ** Operand2 = Result

Example

>>> a=10
>>> b=2
>>> a**b
100
>>> a**3
1000
>>> 2**3
8

7.Floor Division ( // )

The Floor Division operator divides two operands and returns the quotient as a whole number which is the largest possible integer.

Example,

if 10/3 = 3.33333

then, 10//3 will be the the greatest possible integer which is 3 itself.

Syntax

Operand1 // Operand2 = Result

Example

>>> a=10
>>> b=3
>>> a//b
3
>>> a//6
1
>>> 70//8
8

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription