StudyToCert

All certifications / PCEP / Lessons

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

Name scopes, shadowing and the global keyword; UnboundLocalError

▶ Watch the overview video

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

A name's scope is the part of the program where that name can be seen and used. Names assigned at the top level of a script live in the global scope and are visible everywhere in the file, including inside functions. Names created inside a function, including its parameters, are local: they exist only while that call is running and cannot be seen from outside. Using a function's local variable after the function returns raises NameError. Scopes keep functions independent: a variable called total inside one function never collides with a total inside another.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 7 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