Logo

Developer learning path

Python

Arithmetic Operators in Python

Arithmetic Operators

15

#description

Arithmetic operators are used to perform mathematical operations on numerical values in Python.

Python supports several arithmetic operators which include:

  1. Addition (+): This operator is used to add two numbers together.

Example:

                    
a = 5
b = 10
c = a + b
print(c)  # Output: 15
                  
  1. Subtraction (-): This operator is used to subtract one number from another.

Example:

                    
a = 10
b = 2
c = a - b
print(c)  # Output: 8
                  
  1. Multiplication (*): This operator is used to multiply two numbers together.

Example:

                    
a = 3
b = 6
c = a * b
print(c)  # Output: 18
                  
  1. Division (/): This operator is used to divide a number by another number.

Example:

                    
a = 9
b = 3
c = a / b
print(c)  # Output: 3.0
                  
  1. Modulus (%): This operator is used to find the remainder of dividing one number by another number.

Example:

                    
a = 11
b = 3
c = a % b
print(c)  # Output: 2
                  
  1. Floor Division (//): Similar to division, but rounds down the result to the nearest integer.

Example:

                    
a = 15
b = 2
c = a // b
print(c)  # Output: 7
                  
  1. Exponentiation (**): This operator raises a number to the power of another number.

Example:

                    
a = 2
b = 3
c = a ** b
print(c)  # Output: 8
                  

These arithmetic operators can be used with variables or directly with numerical values. It is important to note that some operations may result in errors, such as division by zero, and should be avoided.

March 25, 2023

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.