Which data structure from the collections module is best suited for efficiently keeping track of element frequencies?
collections
OrderedDict
Counter
deque
defaultdict
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's a placeholder that doesn't have any specific purpose.
It stores the return value of the method.
It refers to the current instance of the class, allowing access to instance variables and methods.
What will the following code snippet print?
d = {} d.setdefault('a', []).append(1) print(d['a'])
[]
1
KeyError: 'a'
[1]
What does inheritance allow in object-oriented programming?
Creating new classes that inherit properties and methods from existing classes.
Defining methods with the same name but different implementations in different classes.
Creating objects of one class inside another class.
Restricting access to certain data and methods within a class.
Which concept in OOP emphasizes providing a simplified view of an object, hiding its complexity?
Abstraction
Polymorphism
Encapsulation
Inheritance
In a function definition, what is the order in which you should define different types of arguments?
*args, positional arguments, **kwargs, keyword arguments
keyword arguments, *args, positional arguments, **kwargs
**kwargs, keyword arguments, *args, positional arguments
positional arguments, keyword arguments, *args, **kwargs
How do you create an instance of a class named 'Dog' in Python?
my_dog = Dog()```
Dog = new()```
create Dog()```
Dog.new()```
How can you get the current date and time using the 'datetime' module?
datetime.now
datetime.today()
datetime.datetime.now()
datetime.currentTime()
How can you handle potential errors when opening a file in Python?
Using an if-else statement.
Using a try-except block.
Using a for loop.
Using a while loop.
What differentiates a deque from a regular Python list?
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.