Exercise: Python

Questions for: Functions

What does the locals() function return?
A:
The local variables in the current namespace.
B:
The global variables in the current namespace.
C:
The names of all variables in the current namespace.
D:
The values of all variables in the current namespace.
Answer: A
The locals() function in Python returns a dictionary representing the local variables in the current namespace.
What is the purpose of the itertools.chain function?
A:
To concatenate two lists.
B:
To chain multiple iterables into a single iterable.
C:
To filter elements from an iterable.
D:
To create a chain of functions.
Answer: B
The itertools.chain function in Python is used to chain multiple iterables into a single iterable.
What does the __slots__ attribute do in a Python class?
A:
It specifies the slots where the class instances are stored.
B:
It restricts the creation of new attributes in class instances.
C:
It defines the initial values of attributes in class instances.
D:
It allows for dynamic creation of attributes in class instances.
Answer: B
The __slots__ attribute in Python is used to restrict the creation of new attributes in class instances.
What is the purpose of the super() function?
A:
To access the superclass of a class.
B:
To call the constructor of the superclass.
C:
To create an instance of the superclass.
D:
To check if an object is a superclass.
Answer: A
The super() function in Python is used to access the superclass of a class, allowing you to call methods from the superclass.
What does the isinstance function check for?
A:
It checks if an object is an instance of a specific class.
B:
It checks if an object is iterable.
C:
It checks if an object is callable.
D:
It checks if an object is a string.
Answer: A
The isinstance function in Python checks if an object is an instance of a specific class.
Ad Slot (Above Pagination)
Quiz