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. 📝
+)-)*)/)%)**)<a name="addition"></a>
+)The + operator in Python is used for addition. Let's see an example:
# Example of addition
a = 5
b = 3
sum = a + b
print(sum) # Output: 8In 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>
-)The - operator in Python is used for subtraction. Let's see an example:
# Example of subtraction
a = 10
b = 3
difference = a - b
print(difference) # Output: 7In 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>
*)The * operator in Python is used for multiplication. Let's see an example:
# Example of multiplication
a = 5
b = 3
product = a * b
print(product) # Output: 15In 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>
/)The / operator in Python is used for division. Let's see an example:
# Example of division
a = 10
b = 2
quotient = a / b
print(quotient) # Output: 5.0In 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>
%)The % operator in Python is used for finding the modulus, or remainder, of division. Let's see an example:
# Example of modulus
a = 10
b = 3
remainder = a % b
print(remainder) # Output: 1In 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>
**)The ** operator in Python is used for exponentiation. Let's see an example:
# Example of exponentiation
a = 2
b = 3
power = a ** b
print(power) # Output: 8In 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>
What is the result of `5 + 3` in Python?
What is the result of `10 - 3` in Python?
What is the result of `5 * 3` in Python?
What is the result of `10 / 2` in Python?
What is the result of `10 % 3` in Python?
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! ✅