Skip to content

Python arithmetic operations

  • by

Python arithmetic operations refer to the mathematical operations that can be performed using arithmetic operators in the Python programming language. These operations allow you to perform calculations and manipulate numerical data in your Python programs.

Here’s a tabular format summarizing:

OperationOperatorExampleResult
Addition+2 + 35
Subtraction5 – 23
Multiplication*2 * 36
Division/10 / 25.0
Floor Division//10 // 33
Modulo%10 % 31
Exponentiation**2 ** 38

These operations can be used with numeric data types such as integers and floating-point numbers. Python also allows the use of parentheses to control the order of evaluation and perform complex calculations.

Python arithmetic operations example

Here’s an example that demonstrates the use of arithmetic operations in Python:

# Addition
a = 2
b = 3
sum_result = a + b
print("Sum:", sum_result)  # Output: Sum: 5

# Subtraction
x = 5
y = 2
difference_result = x - y
print("Difference:", difference_result)  # Output: Difference: 3

# Multiplication
p = 2
q = 3
product_result = p * q
print("Product:", product_result)  # Output: Product: 6

# Division
m = 10
n = 2
division_result = m / n
print("Division:", division_result)  # Output: Division: 5.0

# Floor Division
c = 10
d = 3
floor_division_result = c // d
print("Floor Division:", floor_division_result)  # Output: Floor Division: 3

# Modulo
e = 10
f = 3
modulo_result = e % f
print("Modulo:", modulo_result)  # Output: Modulo: 1

# Exponentiation
g = 2
h = 3
exponentiation_result = g ** h
print("Exponentiation:", exponentiation_result)  # Output: Exponentiation: 8

Output:

Python arithmetic operations

The results of each operation are then printed to the console.

Do comment if you have any doubts or suggestions on this Python basic tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *