Python Arithmetic Operators Example

Here, we are going to learn about the arithmetic operators in Python and writing a Python program to demonstrate the example for arithmetic operators.
Submitted by Shivang Yadav, on March 22, 2021

Python Arithmetic Operators

Following are the Arithmetic Operators (also known as Mathematical Operators) in Python which are used to perform the arithmetic operations,

Operator Name Description Example
a=10,b=20
+ Addition Returns the addition of two numbers a+b=30
- Subtraction Returns the subtraction of two numbers a-b = -10
* Multiplication Returns the product (multiplication) of two numbers a*b = 30
/ Division Returns the result of the divide operation of two numbers a = 10,b=3
a/b=3.333
% Modulus Returns the remainder of the two numbers a=10,b=3
a%b=1
** Exponent Returns the result of exponential operation of two numbers a=2, b= 3
a**b = 8
// Floor division Returns the result of the floor division i.e., returns the result without decimal points for positive numbers and returns the floored value if any of the operands is negative a=10,b=3
a//b=3
a=10,b=-3
a//b=-4

Python program to demonstrate the example for arithmetic operators

# Python program to demonstrate the 
# example of arithmetic operators

a = 10
b = 3

# addition
result = a+b
print("a+b :", result)

# subtraction
result = a-b
print("a-b :", result)

# division
result = a/b
print("a/b :", result)

# modulus
result = a%b
print("a%b :", result)

# exponent
result = a**b
print("a**b :", result)

# floor division
result = a//b
print("a//b :", result)

# updating the values of a & b 
a = -10
b = 3
print("a:", a, "b:", b)
result = a//b
print("a//b :", result)

Output:

a+b : 13
a-b : 7
a/b : 3.3333333333333335
a%b : 1
a**b : 1000
a//b : 3
a: -10 b: 3
a//b : -4

Python Basic Programs »





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.