Q:

Python Arithmetic Operators Example

belongs to collection: Python basic programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to print ASCII value of a character... >>
<< Python program to find addition of two numbers (4 ...