Python Arithmetic Operators 🎯

beginner
25 min

Python Arithmetic Operators 🎯

Welcome to CodeYourCraft's Python Arithmetic Operators tutorial! In this lesson, we'll dive into the world of basic mathematical operations and learn how to perform them using Python. By the end of this lesson, you'll have a solid foundation to build upon as you continue your Python journey. 📝

Table of Contents

  1. Addition (+)
  2. Subtraction (-)
  3. Multiplication (*)
  4. Division (/)
  5. Modulus (%)
  6. Exponentiation (**)
  7. Quiz: Arithmetic Operators Practice

<a name="addition"></a>

1. Addition (+)

The + operator in Python is used for addition. Let's see an example:

python
# Example of addition a = 5 b = 3 sum = a + b print(sum) # Output: 8

In this example, we've defined two variables a and b with values 5 and 3 respectively. We then use the + operator to add them and store the result in a new variable sum. Finally, we print the result.


<a name="subtraction"></a>

2. Subtraction (-)

The - operator in Python is used for subtraction. Let's see an example:

python
# Example of subtraction a = 10 b = 3 difference = a - b print(difference) # Output: 7

In this example, we've defined two variables a and b with values 10 and 3 respectively. We then use the - operator to subtract b from a and store the result in a new variable difference. Finally, we print the result.


<a name="multiplication"></a>

3. Multiplication (*)

The * operator in Python is used for multiplication. Let's see an example:

python
# Example of multiplication a = 5 b = 3 product = a * b print(product) # Output: 15

In this example, we've defined two variables a and b with values 5 and 3 respectively. We then use the * operator to multiply them and store the result in a new variable product. Finally, we print the result.


<a name="division"></a>

4. Division (/)

The / operator in Python is used for division. Let's see an example:

python
# Example of division a = 10 b = 2 quotient = a / b print(quotient) # Output: 5.0

In this example, we've defined two variables a and b with values 10 and 2 respectively. We then use the / operator to divide a by b and store the result in a new variable quotient. Finally, we print the result.


<a name="modulus"></a>

5. Modulus (%)

The % operator in Python is used for finding the modulus, or remainder, of division. Let's see an example:

python
# Example of modulus a = 10 b = 3 remainder = a % b print(remainder) # Output: 1

In this example, we've defined two variables a and b with values 10 and 3 respectively. We then use the % operator to find the remainder when a is divided by b. Finally, we print the result.


<a name="exponentiation"></a>

6. Exponentiation (**)

The ** operator in Python is used for exponentiation. Let's see an example:

python
# Example of exponentiation a = 2 b = 3 power = a ** b print(power) # Output: 8

In this example, we've defined two variables a and b with values 2 and 3 respectively. We then use the ** operator to raise a to the power of b. Finally, we print the result.


<a name="quiz"></a>

7. Quiz: Arithmetic Operators Practice 💡

Quick Quiz
Question 1 of 1

What is the result of `5 + 3` in Python?

Quick Quiz
Question 1 of 1

What is the result of `10 - 3` in Python?

Quick Quiz
Question 1 of 1

What is the result of `5 * 3` in Python?

Quick Quiz
Question 1 of 1

What is the result of `10 / 2` in Python?

Quick Quiz
Question 1 of 1

What is the result of `10 % 3` in Python?

Quick Quiz
Question 1 of 1

What is the result of `2 ** 3` in Python?

That's it for today! In the next lesson, we'll dive deeper into Python and explore more topics. Keep practicing and happy coding! ✅