Questions and Answers Graded A+
What is the difference between a local variable and a global variable?
✔✔ A local variable is defined inside a function and can only be accessed there, while a global
variable is defined outside any function and can be accessed anywhere in the program.
How do you specify that a function should use a global variable?
✔✔ Use the `global` keyword before the variable name.
What is a docstring in Python?
✔✔ A string used to describe what a function does, enclosed in triple quotes.
How can you pass multiple arguments to a function?
✔✔ Separate them with commas in the function call and definition.
What is the purpose of keyword arguments in a function call?
✔✔ They allow you to specify arguments by name, making the call more readable.
1
, What is the purpose of a default parameter value in a function?
✔✔ To provide a value that will be used if no argument is passed for that parameter.
How do you specify a default parameter value?
✔✔ Assign a value to the parameter in the function definition.
Can a function return multiple values in Python?
✔✔ Yes, using a tuple, list, or dictionary.
What is a recursive function?
✔✔ A function that calls itself to solve a problem.
What is an example use case for a recursive function?
✔✔ Calculating the factorial of a number.
What is the base case in recursion?
✔✔ The condition that stops the recursive calls.
2