In Python, how do you access an instance variable within a class method?
Directly using the variable name.
Using the class name followed by the variable name.
Using the 'self' keyword followed by the variable name.
Instance variables cannot be accessed within class methods.
Which data structure from the collections module is best suited for efficiently keeping track of element frequencies?
collections
deque
defaultdict
OrderedDict
Counter
What is a key characteristic of a closure in Python?
It forces a function to return a value of a specific data type.
It allows a nested function to 'remember' and access variables from its enclosing function's scope even after the outer function has finished executing.
It prevents a function from accessing global variables.
It allows a function to be defined inside a class.
What is the primary benefit of organizing Python code into modules and packages?
Faster code execution speed
Reduced memory consumption during execution
Improved code readability and organization
Elimination of the need for comments
In a function definition, what is the order in which you should define different types of arguments?
keyword arguments, *args, positional arguments, **kwargs
**kwargs, keyword arguments, *args, positional arguments
*args, positional arguments, **kwargs, keyword arguments
positional arguments, keyword arguments, *args, **kwargs
How can you access the constant 'pi' from the 'math' module after importing it?
math.pi
math(pi)
math->pi
pi
Which module is used to work with CSV (Comma Separated Values) files in Python?
csv
file
text
data
What is the main goal of encapsulation in object-oriented programming?
To define a common interface for a set of related classes.
To create objects with multiple forms and behaviors.
To enable code reuse by inheriting from existing classes.
To hide the internal implementation details of a class from the outside world.
What is a key difference between OrderedDict and a regular dictionary in Python?
OrderedDict is mutable, while regular dictionaries are immutable.
OrderedDict supports list comprehensions for creating dictionaries, while regular dictionaries do not.
OrderedDict preserves the order of key insertion, while regular dictionaries do not guarantee order.
OrderedDict allows duplicate keys, while regular dictionaries do not.
What is the purpose of the 'r' prefix in a regular expression pattern?
It enables multiline matching.
It performs a greedy match.
It makes the pattern case-insensitive.
It treats the pattern as a raw string, ignoring escape sequences.