Loops Functions 🔁🧠
These two concepts are key to writing clean, efficient, and reusable code — especially when working with data.
1️⃣ Loops in Python
Loops help you repeat tasks like reading data, checking values, or processing items in a list.
For Loop
fruits = ["apple", "banana", "mango"]
for fruit in fruits:
print(fruit)
While Loop
count = 1
while count <= 3:
print("Loading...", count)
count += 1
Loop with Condition
numbers = [10, 5, 20, 3]
for num in numbers:
if num > 10:
print(num, "is greater than 10")
2️⃣ Functions in Python
Functions let you group code into blocks you can reuse.
Basic Function
def greet(name):
return f"Hello, {name}!"
print(greet("Riya"))
Function with Logic
def is_even(num):
if num % 2 == 0:
return True
return False
print(is_even(4)) # Output: True
Function for Calculation
def square(x):
return x * x
print(square(6)) # Output: 36
✅ Why This Matters in Data Science
• Loops help in iterating over datasets
• Functions make your data cleaning reusable
• Helps organize long analysis code into simple blocks
🎯 Practice Task for You:
• Write a for loop to print numbers from 1 to 10
• Create a function that takes two numbers and returns their average
• Make a function that returns "Even" or "Odd" based on input
💬 Tap ❤️ for more!