Python Foundations

Master the basics of Python programming with practical examples

Getting Started with Variables

Variables are like containers that store data. Let's look at a simple example:

# Creating variables
name = "Alice"
age = 25
is_student = True

print(f"Name: {name}")
print(f"Age: {age}")
print(f"Student: {is_student}")

Data Types Explorer

Python has several built-in data types. Click each type to see examples and common methods:

"Hello, Python!"

Text data enclosed in quotes

.upper()
.lower()
.split()
.strip()

Control Flow

# If statements and loops
for i in range(3):
    if i == 0:
        print("First iteration")
    elif i == 1:
        print("Second iteration")
    else:
        print("Last iteration")

Functions

def calculate_average(numbers):
    """Calculate the average of a list of numbers"""
    return sum(numbers) / len(numbers)

# Example usage
scores = [85, 92, 78, 90, 88]
avg = calculate_average(scores)
print(f"Average score: {avg}")

Practical Tips

Google Colab Tips

  • • Use Shift + Enter to run cells
  • • Save your work frequently
  • • Use markdown cells for notes

Best Practices

  • • Use meaningful variable names
  • • Add comments to explain complex logic
  • • Keep functions focused and simple