What is the most efficient way to concatenate a large number of strings in Python?
Using the '+' operator.
Using the '%s' operator.
It depends on the size of the strings.
Using the ''.join() method.
What does polymorphism allow objects of different classes to do in Python?
Have different data types for the same variable name
Access private members of each other
Instantiate multiple times with different initial values
Respond to the same method call in their own specific way
What is the output of the following code snippet?
matrix = [[1, 2, 3], [4, 5, 6]] print(matrix[0][2])
1
2
3
IndexError: list index out of range
What differentiates a deque from a regular Python list?
deque
Deques are thread-safe, while lists are not.
Deques are immutable, while lists are mutable.
Deques are optimized for appending and popping elements from both ends, while lists are optimized for operations at the end.
Deques can only store integers, while lists can store any data type.
How can you access the constant 'pi' from the 'math' module after importing it?
math.pi
pi
math->pi
math(pi)
Which regular expression will match any string that starts with 'a' and ends with 'z'?
'^a.+z$'
'^a.*z$'
'a.+z'
'a.*z'
What is the output of the following Python code?
with open('data.txt', 'w') as file: file.write('Hello, world!') print(file.read())
The code will raise a ValueError.
The code will print nothing.
The code will raise an IOError.
Hello, world!
Which of the following is a characteristic of encapsulation in Object-Oriented Programming?
Bundling data and methods that operate on that data into a single unit (a class)
Preventing the use of inheritance
Allowing direct modification of an object's internal state from anywhere in the program
Exposing all data and methods publicly
How can you get the current date and time using the 'datetime' module?
datetime.today()
datetime.datetime.now()
datetime.now
datetime.currentTime()
How can you handle potential errors when opening a file in Python?
Using a for loop.
Using a try-except block.
Using a while loop.
Using an if-else statement.