Which module would you use to interact with the operating system, like creating directories?
os
math
sys
datetime
What does polymorphism allow objects of different classes to do in Python?
Have different data types for the same variable name
Respond to the same method call in their own specific way
Instantiate multiple times with different initial values
Access private members of each other
What is the purpose of the OrderedDict class in Python?
OrderedDict
It optimizes dictionary lookups for faster retrieval of values.
It prevents duplicate keys from being added to a dictionary.
It allows you to create dictionaries with keys as immutable data types only.
It provides a dictionary that remembers the order in which keys were inserted.
What is a key difference between instance methods and class methods in Python?
Instance methods operate on specific instances of a class, while class methods operate on the class itself.
Instance methods are defined using the 'classmethod' decorator, while class methods use the 'staticmethod' decorator.
Class methods can access instance variables, while instance methods cannot access class variables.
There is no practical difference; both can be used interchangeably.
Which code snippet correctly creates a dictionary where keys are numbers from 1 to 5 and values are their squares using a dictionary comprehension?
[num: num**2 for num in range(1, 6)]
{num: num**2 for num in range(1, 6)}
{num**2: num for num in range(1, 6)}
(num: num**2 for num in range(1, 6))
How can you write a multiline string in Python?
Using double quotes (")
Using triple single quotes (''') or triple double quotes (""")
Using backslash ()
Using single quotes (')
Which regular expression will match any string that starts with 'a' and ends with 'z'?
'a.*z'
'^a.*z$'
'^a.+z$'
'a.+z'
Which statement correctly imports the 'math' module in Python?
include math
require math
using math
import math
How do you create an instance of a class named 'Dog' in Python?
create Dog()```
Dog = new()```
Dog.new()```
my_dog = Dog()```
What is the primary role of the 'self' parameter in Python class methods?
It's a placeholder that doesn't have any specific purpose.
It stores the return value of the method.
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.