Skip to content
CCC Python Course

Functions and scope

Stage
1
Module
M1.10
Lessons
1

In this module

  • Wrap repeated logic in a function with def, taking parameters and returning a result.
  • Tell a local variable from a global one, and use global to change a global from inside a function.
  • Avoid the mutable-default-argument trap, where a default list or dict persists between calls.
  • Write a short one-line function with lambda.

Before this module

Lessons

  1. 1Functions and scope

Practice

Try this on the judge. The link opens the problem on WMOJ.

  1. 2023 J5
    CCC Word Hunt (opens on WMOJ in a new tab) WMOJ

    Search a small grid for a hidden word along a single horizontal line, the easiest of several scoring tiers.