Lesson 1: Indentation and Whitespace 📘

Learning Target: I can use indentation and whitespace to structure my code.

Python uses indentation to define blocks of code. Proper indentation is crucial for the code to run correctly.

def greet(name):
    print(f"Hello, {name}!")

greet("Alice")

Your Turn!

Write a function that takes a number and prints whether it's even or odd. Make sure to use proper indentation.

Try it here:

Lesson 2: Writing Comments 📝

Learning Target: I can write comments to explain my code.

Comments are lines in the code that are ignored by Python but help humans understand the code.

# This is a comment
print("Hello, world!")  # This prints a message

Your Turn!

Write a small program with at least two comments that explain what each part does.

Try it here:

Lesson 3: Using Docstrings 📚

Learning Target: I can use docstrings to document my functions.

Docstrings are special comments used to describe the purpose of a function or module.

def add(a, b):
    """
    This function adds two numbers.
    :param a: First number
    :param b: Second number
    :return: Sum of a and b
    """
    return a + b

Your Turn!

Write a function with a docstring that explains what the function does and its parameters.

Try it here:

Lesson 4: Generating Documentation with pydoc 📖

Learning Target: I can generate documentation using pydoc.

pydoc is a module that automatically generates documentation from docstrings.

# Run this command in the terminal to generate documentation
# python -m pydoc -w mymodule

Your Turn!

Create a module with functions that have docstrings. Use pydoc to generate the documentation.

Try it here: