In Python, what is the difference between a class variable and an instance variable?
There is no difference; they are interchangeable terms.
Class variables are declared inside a method, while instance variables are declared outside methods.
Class variables are shared by all instances of a class, while instance variables are unique to each instance.
Class variables can only store integers, while instance variables can store any data type.
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**2: num for num in range(1, 6)}
{num: num**2 for num in range(1, 6)}
(num: num**2 for num in range(1, 6))
What is the purpose of the 'r' prefix in a regular expression pattern?
It makes the pattern case-insensitive.
It treats the pattern as a raw string, ignoring escape sequences.
It performs a greedy match.
It enables multiline matching.
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 stores the return value of the method.
It's a placeholder that doesn't have any specific purpose.
It refers to the current instance of the class, allowing access to instance variables and methods.
Which statement correctly imports the 'math' module in Python?
using math
require math
import math
include math
What differentiates a deque from a regular Python list?
deque
Deques can only store integers, while lists can store any data type.
Deques are immutable, while lists are mutable.
Deques are thread-safe, while lists are not.
Deques are optimized for appending and popping elements from both ends, while lists are optimized for operations at the end.
What is the purpose of the 'init.py' file in a Python package?
Stores the package's documentation
Defines the package's main function
Contains unit tests for the package
Marks the directory as a Python package
What does the 'sys.argv' list in Python store?
Command line arguments passed to the script
System error messages
Contents of the current working directory
Environment variables
What is the most efficient way to concatenate a large number of strings in Python?
Using the '%s' operator.
Using the ''.join() method.
It depends on the size of the strings.
Using the '+' operator.
In a function definition, what is the order in which you should define different types of arguments?
positional arguments, keyword arguments, *args, **kwargs
keyword arguments, *args, positional arguments, **kwargs
**kwargs, keyword arguments, *args, positional arguments
*args, positional arguments, **kwargs, keyword arguments