Chapter 5 Questions and Answers
Already Passed
What will happen if a recursive function has no base case?
✔✔It will result in infinite recursion and eventually cause a stack overflow error.
What is the purpose of a function header?
✔✔To define the function’s name, parameters, and any default values.
What is the purpose of a function docstring?
✔✔To provide a description of what the function does.
How can you access the docstring of a function?
✔✔Using the `__doc__` attribute of the function.
What does it mean to pass an argument by value?
✔✔The function gets a copy of the argument, and changes inside the function do not affect the
original value.
1
, What does it mean to pass an argument by reference?
✔✔The function gets access to the actual argument, and changes inside the function can affect
the original value.
What is a local variable?
✔✔A variable declared inside a function, accessible only within that function.
What is a global variable?
✔✔A variable declared outside any function, accessible throughout the program.
Why is it recommended to avoid excessive use of global variables?
✔✔Because they make the code harder to debug and maintain.
How can you pass multiple arguments to a function?
✔✔By separating the arguments with commas inside the parentheses.
What is the default value for a function parameter?
2