Master the basics of Python programming with practical examples
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}")
Python has several built-in data types. Click each type to see examples and common methods:
Text data enclosed in quotes
# 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")
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}")