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.
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.