Python Programming - Functions

Exercise : Functions - General Questions
  • Functions - General Questions
26.
What does the term "anonymous function" refer to?
A function with no parameters
A function that doesn't return any value
A function without a name
A function with a single line of code
Answer: Option
Explanation:
An anonymous function in Python refers to a function without a name, often created using the lambda keyword.

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

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

28.
What is the purpose of the ord() function?
Returns the ASCII value of a character
Computes the power of a number
Converts a string to uppercase
Checks if a variable is of a certain type
Answer: Option
Explanation:
The ord() function returns the ASCII value of a character.

29.
What is the purpose of the sorted() function?
Sorts elements of a list in ascending order
Reverses the order of elements in a list
Shuffles elements randomly in a list
Checks if a variable is of a certain type
Answer: Option
Explanation:
The sorted() function is used to sort the elements of an iterable, such as a list, in ascending order.

30.
What is the purpose of the locals() function?
Retrieves a list of local variables
Converts a string to lowercase
Checks if a variable is of a certain type
Retrieves a dictionary of local symbols
Answer: Option
Explanation:
The locals() function returns a dictionary representing the current local symbol table.