You need to use a data structure as keys for a dictionary, and it must hold multiple items. Which one would you choose between lists and tuples?

  • Both lists and tuples
  • List
  • Neither lists nor tuples
  • Tuple
Tuples are the preferred choice as keys for dictionaries because they are immutable. Lists, on the other hand, are mutable and cannot be used as dictionary keys. Immutability ensures that the keys remain consistent, preventing unexpected behavior in the dictionary.

To write a list of dictionaries to a CSV file, one can use the DictWriter class from the _______ module.

  • csv
  • data
  • excel
  • pandas
To write a list of dictionaries to a CSV file in Python, you can use the csv module. Specifically, the DictWriter class from the csv module allows you to write dictionaries as rows in a CSV file, where the keys of the dictionaries are used as column headers. This is a common technique when working with tabular data in Python.

For method overriding to occur, the method in the derived class must have the same _______ and return type as the method in the base class.

  • Method name and arguments
  • Method name and parameters
  • Method signature and name
  • Method signature and parameters
Method overriding in Python requires that the method in the derived class has the same method name and arguments (parameters) as the method in the base class.

In type hinting, if a function is expected not to return any value, the return type should be hinted as _______.

  • Empty
  • None
  • Void
  • nan
In type hinting, if a function is expected not to return any value, the return type should be hinted as 'None'. 'None' signifies the absence of a return value.

Which built-in Python function can be used to determine if a class is a subclass of another?

  • inheritsfrom()
  • instanceof()
  • issubclass()
  • subclassof()
You can use the 'issubclass()' built-in function in Python to determine if a class is a subclass of another. This function takes two arguments: the derived class and the base class. If the derived class is indeed a subclass of the base class, it returns True; otherwise, it returns False. This function is commonly used for checking class hierarchies and relationships.

The _______ method in a context manager returns the resource that will be managed.

  • enter()
  • exit()
  • init()
  • resource()
The 'enter()' method in a context manager returns the resource that will be managed. It is called when entering the 'with' block.

Which method is used to remove a key-value pair from a dictionary by specifying the key?

  • delete()
  • pop()
  • popitem()
  • remove()
The pop() method is used to remove a key-value pair from a dictionary by specifying the key. It returns the value associated with the key and removes the key-value pair from the dictionary. The del statement can also be used to delete a key-value pair by specifying the key. The popitem() method removes and returns an arbitrary key-value pair, while remove() is not a standard dictionary method.

In which type of loop structures can the break statement be used in Python?

  • both for and while loops
  • for loop
  • neither for nor while loops
  • while loop
The 'break' statement can be used in both 'for' and 'while' loops in Python. It is used to exit the loop prematurely based on a certain condition, making it a useful control structure for loop termination.

How does the break statement affect the else clause associated with a loop?

  • It executes the else clause
  • It has no impact
  • It raises an error
  • It skips the else clause
In Python, the 'break' statement, when executed within a loop, skips the 'else' clause associated with the loop.

How can you call (or invoke) a function named example?

  • call example()
  • example()
  • execute example{}
  • invoke(example)
To call (or invoke) a function named 'example' in Python, you use the function name followed by parentheses, like this: 'example()'.