What differentiates a deque from a regular Python list?
deque
Deques can only store integers, while lists can store any data type.
Deques are optimized for appending and popping elements from both ends, while lists are optimized for operations at the end.
Deques are immutable, while lists are mutable.
Deques are thread-safe, while lists are not.
What does the csv.reader() function in Python return?
csv.reader()
A string containing the entire CSV file content.
A list of dictionaries.
A list of strings.
A list of lists, representing rows and cells.
What does the 're.findall()' function return?
A boolean value indicating whether the pattern is present in the string.
The first match of the pattern in the string.
A list of all non-overlapping matches of the pattern in the string.
None of the above.
Which module would you use to interact with the operating system, like creating directories?
os
math
datetime
sys
What does inheritance allow in object-oriented programming?
Creating new classes that inherit properties and methods from existing classes.
Creating objects of one class inside another class.
Defining methods with the same name but different implementations in different classes.
Restricting access to certain data and methods within a class.
Which data structure would be most appropriate for representing a graph in Python?
A set of tuples, where each tuple represents an edge between two nodes.
All of the above options can be used to represent a graph.
A list of lists, where each inner list represents a node and its connections.
A dictionary where keys are nodes, and values are lists of their neighbors.
What is the purpose of using a default argument in a Python function?
To define a variable that can only be accessed within the function.
To create a function that can accept any number of arguments.
To specify a value for an argument if it is not passed in the function call.
To make the function return a default value if no arguments are provided.
In Python, what is the difference between a class variable and an instance variable?
Class variables are declared inside a method, while instance variables are declared outside methods.
There is no difference; they are interchangeable terms.
Class variables can only store integers, while instance variables can store any data type.
Class variables are shared by all instances of a class, while instance variables are unique to each instance.
What is the primary benefit of defining custom exceptions in Python?
To improve code readability by using specific exception types.
To prevent all types of exceptions from occurring.
To reduce the amount of code required for error handling.
To automatically log error messages to a file.
What is the purpose of the finally block in Python exception handling?
finally
It specifies the type of exception to catch.
It defines a custom exception to be raised.
It always executes after a try block, regardless of whether an exception occurred.
try
It executes only if an exception occurs in the try block.