What happens when Python executes a function definition such as def greet():?
4 Functions and Scope Online Quiz Questions
Use this free practice quiz with 20 questions to review 4 Functions and Scope, test your knowledge, and prepare for your next test or exam.
True or false: In def greet_person(name):, name is a parameter, while in greet_person("Maya"), "Maya" is an argument.
- A
True
- B
False
What is the technical term for a string literal placed as the first statement in a function to document its behavior?
If execution reaches the end of a Python function without an explicit return statement, the function returns .
Which statement correctly distinguishes square from square(5)?
- A
squarerefers to the function object, whilesquare(5)calls it. - B
squarecalls the function, whilesquare(5)returns the function object. - C
Both expressions call the function and produce the same result.
- D
Neither expression can refer to a function unless
returnis used.
Which characteristics generally describe a well-designed, reusable function? Select all correct choices.
- A
They perform one main task.
- B
They receive necessary data through parameters.
- C
They rely on hidden global state for important inputs.
- D
They can be tested independently.
What is one benefit of calling a function with keyword arguments?
- A
They require every parameter to have a default value.
- B
They prevent a function from having multiple parameters.
- C
They make calls more explicit and can allow a different argument order.
- D
They cause the function body to execute during definition.
True or false: If a global variable named limit exists, assigning limit = 20 inside a function automatically changes that global variable.
- A
True
- B
False
Given def double(number): return number * 2, what numerical value does double(4) + double(7) produce?
To rebind a module-level variable from inside a function, use ; to rebind a variable in an enclosing function from a nested function, use .
Which are valid reasons to decompose a larger program into smaller functions? Select all correct choices.
- A
It gives each function a focused responsibility.
- B
It allows functions to be reused separately.
- C
It makes problems in individual steps easier to locate.
- D
It requires every function to contain many unrelated operations.
Explain the difference between printing a value and returning a value from a Python function. Include why returning is important when designing reusable functions.
Given def greet_person(name, punctuation="!"), what happens when the function is called as greet_person("Maya")?
- A
greet_person("Maya")uses"!"forpunctuation. - B
greet_person("Maya")raises an error because every parameter must be supplied. - C
The default value is evaluated only after the function returns.
- D
The default value is always replaced by
Nonewhen omitted.
What happens when Python executes a def statement for a function?
- A
The body executes immediately when Python reads the
defstatement. - B
The body executes when the function is called, such as with
greet(). - C
The body executes only when the function is assigned to a variable.
- D
The body executes automatically when the file is imported.
True or false: If a Python function reaches the end of its body without an explicit return statement, the function call returns None.
- A
True
- B
False
Given def greet_person(name): followed by greet_person("Maya"), which statement correctly identifies the parameter and the argument?
- A
nameis the argument, and"Maya"is the parameter. - B
nameis the parameter, and"Maya"is the argument. - C
Both
nameand"Maya"are parameters. - D
Both
nameand"Maya"are arguments.
Which Python keyword must a nested function use to rebind a variable belonging to an enclosing function, as in the counter example?
Why is return generally different from print inside a function?
- A
A returned value can only be displayed, whereas printed output can be used in expressions.
- B
Printing and returning always have identical effects on the caller.
- C
A returned value can be used by the caller in expressions or assignments, whereas printed output is not the function's returned value.
- D
Printing ends the function and returning continues its execution.
Which sequence gives Python's usual name-resolution order from first searched to last searched?
- A
Global, Local, Enclosing, Built-in
- B
Local, Enclosing, Global, Built-in
- C
Local, Global, Enclosing, Built-in
- D
Built-in, Global, Enclosing, Local
What is the exact attribute name through which Python exposes a function's docstring?
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.