Chapter 5 (Functions) Questions and
Answers Graded A+
What does the keyword `def` do in Python?
✔✔It is used to define a new function.
How can you pass information to a function?
✔✔By providing arguments inside the parentheses when calling the function.
Why is it useful to break a program into smaller functions?
✔✔It improves readability, reusability, and simplifies debugging.
What is the scope of a variable defined inside a function?
✔✔It is local to the function and cannot be accessed outside of it.
How can you make a function output something without using `print` inside it?
✔✔By using the `return` statement and handling the output outside the function.
1
, What does it mean to call a function with "positional arguments"?
✔✔Arguments are matched to parameters based on their position in the function call.
What is a default parameter value in a function?
✔✔It is a value assigned to a parameter that is used if no argument is provided.
How can you make a parameter optional in a function?
✔✔By assigning it a default value in the function definition.
What is the difference between `print` and `return` in a function?
✔✔`print` displays output on the screen, while `return` sends a value back to the caller.
How do you document what a function does?
✔✔By writing a docstring inside triple quotes at the beginning of the function.
What happens if you call a function before it is defined?
✔✔You will get a `NameError` because the function is not yet recognized.
2