Exercise: Functions

Questions for: Functions

What does the __annotations__ attribute indicate?
A:
It contains the annotations of a module.
B:
It contains the annotations of a function's parameters.
C:
It contains the annotations of a class.
D:
It contains the annotations of a variable.
Answer: B
The __annotations__ attribute in Python contains the annotations of a function's parameters.
What is the purpose of the staticmethod decorator?
A:
To create static methods that can be called on class instances.
B:
To define methods with default arguments.
C:
To create methods that only work on static variables.
D:
To convert a function to a class method.
Answer: A
The staticmethod decorator in Python is used to create static methods that can be called on class instances.
What is the purpose of the filter function?
A:
To filter elements from an iterable based on a condition.
B:
To filter files in a directory.
C:
To filter out global variables.
D:
To filter out specific functions from a module.
Answer: A
The filter function in Python is used to filter elements from an iterable based on a specified condition.
How does the zip function work?
A:
It compresses files in a directory.
B:
It combines two or more iterables element-wise into tuples.
C:
It extracts files from a zip archive.
D:
It zips together all functions in a module.
Answer: B
The zip function in Python combines two or more iterables element-wise into tuples.
What is the purpose of the functools.partial function?
A:
To create a partial function with default arguments.
B:
To check if a function is recursive.
C:
To create a generator function.
D:
To convert a function to a class method.
Answer: A
The functools.partial function in Python is used to create a partial function with default arguments, reducing the number of arguments needed.
Ad Slot (Above Pagination)
Quiz