# Week 6 at Blockfuse Labs. Mastering Arithmetic & Compound Operators in Python
This week at Blockfuse Labs, we dived deeper into the world of Python programming. Our focus was on two powerful sets of tools: arithmetic operators and compound assignment operators. These are essential building blocks for any developer, as they help manipulate values, perform calculations, and write cleaner, more efficient code.
Let me walk you through what we learned, especially with code examples to help solidify these concepts.
Arithmetic Operators in Python
Arithmetic operators allow you to perform basic math operations such as addition, subtraction, multiplication, and division. Here are the key operators we covered:
+ Addition 5 + 3 = 8
- Subtraction 5 - 3 = 2
* Multiplication 5 * 3 = 15
* Division 5 / 2 = 2.5
* Floor Division 5 // 2 = 2
* Modulus (Remainder) 5 % 2 = 1
* Exponentiation 2 ** 3 = 8
Code Example:
```
a = 10
b = 3
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponent:", a ** b)
```
Compound Assignment Operators
Compound assignment operators are shortcuts that combine an arithmetic operation with assignment (=). Instead of writing x = x + 3, you can simply write x += 3.
Code Example:
```
x = 5
x += 3 # x = x + 3 → x = 8
print("After += 3:", x)
x -= 2 # x = x - 2 → x = 6
print("After -= 2:", x)
x *= 2 # x = x * 2 → x = 12
print("After *= 2:", x)
x /= 4 # x = x / 4 → x = 3.0
print("After /= 4:", x)
x //= 2 # x = x // 2 → x = 1.0
print("After //= 2:", x)
x %= 2 # x = x % 2 → x = 1.0
print("After %= 2:", x)
x **= 3 # x = x ** 3 → x = 1.0
print("After **= 3:", x)
```
Conclusion:
This week’s lesson reinforced the importance of mastering operators in Python. Arithmetic operators are straightforward but powerful, while compound assignment operators make your code shorter and easier to read both are crucial tools for efficient programming.
I’m excited to continue building on these fundamentals as we move ahead. Blockfuse Labs continues to shape us into not just coders, but problem-solvers ready for the real world.