Python Programming - Functions
Exercise : Functions - General Questions
- Functions - General Questions
11.
What is the purpose of the
nonlocal
keyword?
Answer: Option
Explanation:
The
nonlocal
keyword is used to indicate that a variable refers to the nearest enclosing scope that is not global.
12.
What will be the result of the following code snippet?
def power(x, n=2):
return x ** n
result = power(3)
print(result)
Answer: Option
Explanation:
The function
power
calculates the square of the given argument x
by default, and in this case, it squares 3, resulting in 9.
13.
How do you pass a variable number of keyword arguments to a function?
Answer: Option
Explanation:
The
**kwargs
syntax allows a function to accept a variable number of keyword arguments.
14.
What is the purpose of the
map()
function?
Answer: Option
Explanation:
The
map()
function applies a given function to each item in an iterable (e.g., a list).
15.
What does the term "docstring" refer to?
Answer: Option
Explanation:
A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition and is used for documentation.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers