What does inheritance allow in object-oriented programming?
Defining methods with the same name but different implementations in different classes.
Creating new classes that inherit properties and methods from existing classes.
Creating objects of one class inside another class.
Restricting access to certain data and methods within a class.
Which module would you use to interact with the operating system, like creating directories?
datetime
os
math
sys
What is the purpose of the 'r' prefix in a regular expression pattern?
It makes the pattern case-insensitive.
It enables multiline matching.
It treats the pattern as a raw string, ignoring escape sequences.
It performs a greedy match.
How can you handle potential errors when opening a file in Python?
Using an if-else statement.
Using a for loop.
Using a while loop.
Using a try-except block.
What is the output of the following code snippet?
matrix = [[1, 2, 3], [4, 5, 6]] print(matrix[0][2])
2
1
IndexError: list index out of range
3
What is the primary role of the 'self' parameter in Python class methods?
It refers to the class itself, allowing access to class variables.
It refers to the current instance of the class, allowing access to instance variables and methods.
It stores the return value of the method.
It's a placeholder that doesn't have any specific purpose.
Which principle of OOP allows objects of different classes to be treated as objects of a common type?
Abstraction
Inheritance
Encapsulation
Polymorphism
Which regular expression will match any string that starts with 'a' and ends with 'z'?
'a.+z'
'^a.*z$'
'^a.+z$'
'a.*z'
What does the 're.findall()' function return?
None of the above.
A boolean value indicating whether the pattern is present in the string.
A list of all non-overlapping matches of the pattern in the string.
The first match of the pattern in the string.
What does the Counter class from the collections module do?
Counter
collections
Stores key-value pairs in the order of insertion.
Counts the occurrences of elements in an iterable.
Creates dictionaries with a default value for missing keys.
Implements a last-in, first-out (LIFO) data structure.