Exercise: Python

Questions for: Functions

What does the vars function do?
A:
It returns the names of all variables in the local namespace.
B:
It returns the values of all variables in the local namespace.
C:
It returns the names and values of all variables in the local namespace.
D:
It returns the attributes of an object.
Answer: C
The vars function in Python returns a dictionary containing the names and values of all variables in the local namespace.
What does the __name__ attribute represent?
A:
The name of the module.
B:
The name of the function.
C:
The name of the class.
D:
The name of the variable.
Answer: A
The __name__ attribute represents the name of the module in Python.
What does the chr function do?
A:
It checks if an object is a character.
B:
It converts an integer to a character.
C:
It calculates the character length of a string.
D:
It creates a character set.
Answer: B
The chr function in Python converts an integer to the corresponding Unicode character.
What does the callable function check for?
A:
It checks if an object is an instance of a class.
B:
It checks if an object is callable, i.e., can be called as a function.
C:
It checks if an object is iterable.
D:
It checks if an object is a string.
Answer: B
The callable function in Python checks if an object is callable, i.e., can be called as a function.
How does the locals function differ from globals?
A:
locals returns the local namespace, while globals returns the global namespace.
B:
locals returns the global namespace, while globals returns the local namespace.
C:
Both return the same namespace.
D:
Neither locals nor globals return any namespace.
Answer: A
The locals function returns the local namespace, while globals returns the global namespace.
Ad Slot (Above Pagination)
Quiz