StudyToCert

All certifications / PCEP / Lessons

PCEP – Certified Entry-Level Python Programmer PCEP-30-02 · Domain 4: Functions and exceptions

Defining and invoking functions; functions must be defined before they are called

▶ Watch the overview video

Last reviewed September 30, 2026 · Leer en español

You define a function with the def keyword, followed by the function name, a pair of parentheses containing any parameters, and a colon. The indented block below is the function body, and it must contain at least one statement (pass will do). Defining a function does not run the body; it creates a function object and binds it to the name. The body runs only when you call (invoke) the function by writing its name followed by parentheses, with any arguments inside. Each call runs the body from the top, with fresh local variables.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study PCEP for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the PCEP study plan