Python Programming - Functions

Exercise : Functions - General Questions
  • Functions - General Questions
21.
What is the purpose of the min() function?
Finds the minimum value in a list
Rounds a floating-point number down to the nearest integer
Checks if a variable is of a certain type
Converts a string to lowercase
Answer: Option
Explanation:
The min() function is used to find the minimum value among the elements of an iterable, such as a list.

22.
What will be the output of the following code snippet?
def square(x):
    return x ** 2

numbers = [1, 2, 3, 4]
squared_numbers = list(map(square, numbers))
print(squared_numbers)
[1, 4, 9, 16]
[1, 2, 3, 4]
[2, 4, 6, 8]
Error
Answer: Option
Explanation:
The map() function applies the square function to each element in the numbers list.

23.
How do you define a default value for a function parameter?
Using the default() keyword
Using the set_default method
Using the default_value parameter
Using the parameter=default_value syntax
Answer: Option
Explanation:
Default values for function parameters are specified using the parameter=default_value syntax.

24.
What is the purpose of the filter() function?
Filters out odd numbers from a list
Filters out even numbers from a list
Filters elements of an iterable based on a function's result
Checks if a variable is of a certain type
Answer: Option
Explanation:
The filter() function is used to filter elements of an iterable based on whether a function returns True or False.

25.
What does the term "closure" mean?
A function that calls itself
A function that takes a variable number of arguments
A function object that has access to variables in its lexical scope
A function with a return type specified
Answer: Option
Explanation:
A closure is a function object that has access to variables in its lexical scope, even when the function is called outside that scope.