Functions and Modules Flashcards
6 cards from real PCAP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Functions and Modules flashcards as text
What is a closure in Python?
Answer: A function that captures variables from its enclosing scope
A closure is a function that remembers the variables from its enclosing scope even after that scope has exited.
What does the `global` keyword do inside a function?
Answer: Declares that a variable refers to the global scope
`global` tells Python that the variable inside the function refers to the global namespace, not a local one.
What is a decorator in Python?
Answer: A function that wraps another function to add behavior
A decorator is a callable that takes a function and returns a new function with added behavior.
What does the `__name__ == '__main__'` guard do?
Answer: Prevents code from running when the module is imported
Code under `if __name__ == '__main__':` runs only when the script is executed directly, not when imported.
What is a generator function in Python?
Answer: A function using `yield` to produce a sequence lazily
A generator function uses `yield` to produce values one at a time, suspending state between calls.
Which keyword is used in a generator function to produce a value?
Answer: yield
`yield` suspends the function and sends a value to the caller, resuming on the next iteration.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- pythoninstitute.org — Eligibility, fees, exam format, passing score, retake fee, retake policy, score release, time limit, score validity, exam information · verified Oct 2026
- home.pearsonvue.com — Test delivery · verified Oct 2026