Python Tutorial Part 3: Basic Operations and Control Structures

In this article, we'll learn about basic operations and control structures in Python.

Basic Operations

Python supports various arithmetic operations, including addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (**).

Example:

# Addition
result = 10 + 5

# Subtraction
result = 10 - 5

# Multiplication
result = 10 * 5

# Division
result = 10 / 5

# Exponentiation
result = 10 ** 2

These operations can be performed on numeric data types such as integers and floats.

Control Structures

Python provides control structures such as if statements, for loops, and while loops for controlling the flow of a program.

Example:

# If statement
x = 10
if x > 0:
    print("Positive")
elif x == 0:
    print("Zero")
else:
    print("Negative")

# For loop
for i in range(5):
    print(i)

# While loop
i = 0
while i < 5:
    print(i)
    i += 1

These control structures allow you to execute certain blocks of code conditionally or repeatedly based on specific conditions.

Conclusion

Now you know how to perform basic operations and use control structures in Python. In the next article, we'll dive deeper into functions and modules.

Previous Post Next Post