What is the main goal of encapsulation in object-oriented programming?
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.
To define a common interface for a set of related classes.
What does the csv.reader() function in Python return?
csv.reader()
A list of dictionaries.
A string containing the entire CSV file content.
A list of lists, representing rows and cells.
A list of strings.
Which concept in OOP emphasizes providing a simplified view of an object, hiding its complexity?
Abstraction
Inheritance
Encapsulation
Polymorphism
Which module is used to work with CSV (Comma Separated Values) files in Python?
file
data
csv
text
What is the purpose of the 'r' prefix in a regular expression pattern?
It treats the pattern as a raw string, ignoring escape sequences.
It enables multiline matching.
It makes the pattern case-insensitive.
It performs a greedy match.
Consider the function definition: def my_func(a, b=5, *args, **kwargs): .... What does *args achieve?
def my_func(a, b=5, *args, **kwargs): ...
*args
It collects any number of positional arguments into a tuple.
It defines a variable number of default arguments.
It collects any number of keyword arguments into a dictionary.
It enforces that the function must be called with at least two arguments.
Which string method is used to determine if a string ends with a specified suffix?
startswith()
index()
find()
endswith()
What does polymorphism allow objects of different classes to do in Python?
Instantiate multiple times with different initial values
Respond to the same method call in their own specific way
Have different data types for the same variable name
Access private members of each other
What is a key difference between OrderedDict and a regular dictionary in Python?
OrderedDict
OrderedDict allows duplicate keys, while regular dictionaries do not.
OrderedDict preserves the order of key insertion, while regular dictionaries do not guarantee order.
OrderedDict is mutable, while regular dictionaries are immutable.
OrderedDict supports list comprehensions for creating dictionaries, while regular dictionaries do not.
How do you create a custom exception class in Python?
By creating a new instance of the Exception class.
Exception
By defining a new class that inherits from the BaseException class or one of its subclasses.
BaseException
By using the define_exception() keyword.
define_exception()
By using the custom_exception() function.
custom_exception()