Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

What happens when Python executes a function definition such as def greet():?

  1. A

    The function body runs immediately when Python reads def.

  2. B

    The function body runs when the function is called.

  3. C

    The function body runs only when the program ends.

  4. D

    The function body runs when the function is imported, even if it is never called.

02
True or false
1 point

True or false: In def greet_person(name):, name is a parameter, while in greet_person("Maya"), "Maya" is an argument.

  1. A

    True

  2. B

    False

03
Written response
1 point

What is the technical term for a string literal placed as the first statement in a function to document its behavior?

04
Fill in the blank
1 point

If execution reaches the end of a Python function without an explicit return statement, the function returns .

05
Choose one
1 point

Which statement correctly distinguishes square from square(5)?

  1. A

    square refers to the function object, while square(5) calls it.

  2. B

    square calls the function, while square(5) returns the function object.

  3. C

    Both expressions call the function and produce the same result.

  4. D

    Neither expression can refer to a function unless return is used.

06
Choose all
1 point

Which characteristics generally describe a well-designed, reusable function? Select all correct choices.

  1. A

    They perform one main task.

  2. B

    They receive necessary data through parameters.

  3. C

    They rely on hidden global state for important inputs.

  4. D

    They can be tested independently.

07
Choose one
1 point

What is one benefit of calling a function with keyword arguments?

  1. A

    They require every parameter to have a default value.

  2. B

    They prevent a function from having multiple parameters.

  3. C

    They make calls more explicit and can allow a different argument order.

  4. D

    They cause the function body to execute during definition.

08
True or false
1 point

True or false: If a global variable named limit exists, assigning limit = 20 inside a function automatically changes that global variable.

  1. A

    True

  2. B

    False

09
Written response
1 point

Given def double(number): return number * 2, what numerical value does double(4) + double(7) produce?

10
Fill in the blank
1 point

To rebind a module-level variable from inside a function, use ; to rebind a variable in an enclosing function from a nested function, use .

11
Choose all
1 point

Which are valid reasons to decompose a larger program into smaller functions? Select all correct choices.

  1. A

    It gives each function a focused responsibility.

  2. B

    It allows functions to be reused separately.

  3. C

    It makes problems in individual steps easier to locate.

  4. D

    It requires every function to contain many unrelated operations.

12
Open ended
1 point

Explain the difference between printing a value and returning a value from a Python function. Include why returning is important when designing reusable functions.

13
Choose one
1 point

Given def greet_person(name, punctuation="!"), what happens when the function is called as greet_person("Maya")?

  1. A

    greet_person("Maya") uses "!" for punctuation.

  2. B

    greet_person("Maya") raises an error because every parameter must be supplied.

  3. C

    The default value is evaluated only after the function returns.

  4. D

    The default value is always replaced by None when omitted.

14
Choose one
1 point

What happens when Python executes a def statement for a function?

  1. A

    The body executes immediately when Python reads the def statement.

  2. B

    The body executes when the function is called, such as with greet().

  3. C

    The body executes only when the function is assigned to a variable.

  4. D

    The body executes automatically when the file is imported.

15
True or false
1 point

True or false: If a Python function reaches the end of its body without an explicit return statement, the function call returns None.

  1. A

    True

  2. B

    False

16
Choose one
1 point

Given def greet_person(name): followed by greet_person("Maya"), which statement correctly identifies the parameter and the argument?

  1. A

    name is the argument, and "Maya" is the parameter.

  2. B

    name is the parameter, and "Maya" is the argument.

  3. C

    Both name and "Maya" are parameters.

  4. D

    Both name and "Maya" are arguments.

17
Written response
1 point

Which Python keyword must a nested function use to rebind a variable belonging to an enclosing function, as in the counter example?

18
Choose one
1 point

Why is return generally different from print inside a function?

  1. A

    A returned value can only be displayed, whereas printed output can be used in expressions.

  2. B

    Printing and returning always have identical effects on the caller.

  3. C

    A returned value can be used by the caller in expressions or assignments, whereas printed output is not the function's returned value.

  4. D

    Printing ends the function and returning continues its execution.

19
Choose one
1 point

Which sequence gives Python's usual name-resolution order from first searched to last searched?

  1. A

    Global, Local, Enclosing, Built-in

  2. B

    Local, Enclosing, Global, Built-in

  3. C

    Local, Global, Enclosing, Built-in

  4. D

    Built-in, Global, Enclosing, Local

20
Written response
1 point

What is the exact attribute name through which Python exposes a function's docstring?