Python Functions Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
What is a docstring in Python functions?
Answer: Option A
Explanation: A docstring is a string literal that occurs as the first statement in a function and is used for documentation.
Q12
How can you access a function"s docstring?
Answer: Option B
Explanation: Docstrings can be accessed using the __doc__ attribute or the help() function.
Q13
What is the scope of variables defined inside a function?
Answer: Option B
Explanation: Variables defined inside a function have local scope and are not accessible outside the function.
Q14
Which keyword is used to modify a global variable inside a function?
Answer: Option A
Explanation: The "global" keyword is used to declare that a variable inside a function refers to a global variable.
Q15
What is a recursive function?
Answer: Option B
Explanation: A recursive function is a function that calls itself during its execution.
Q16
What is the purpose of the "nonlocal" keyword?
Answer: Option B
Explanation: The "nonlocal" keyword is used to work with variables in nested functions, where the variable should belong to the outer function.
Q17
What is function overloading in Python?
Answer: Option B
Explanation: Python doesn"t support traditional function overloading like other languages. The last defined function with the same name will override previous ones.
Q18
What is a generator function?
Answer: Option B
Explanation: Generator functions use yield instead of return and return an iterator that can be iterated over.
Q19
What is the difference between parameters and arguments?
Answer: Option A
Explanation: Parameters are variables in the function definition, while arguments are the actual values passed to the function.
Q20
What are default parameters in Python functions?
Answer: Option B
Explanation: Default parameters are parameters that have default values if no argument is provided for them.