For loops in Python utilize the ______ method internally to iterate over items.

  • enumerate
  • iterate
  • loop
  • range
For loops in Python utilize the enumerate method internally to iterate over items. enumerate returns both the index and the value of each item in the sequence, making it useful for tracking positions in the loop.

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.

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.

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.

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.

In terms of function execution, what is the difference between yield and return?

  • 'return' immediately terminates the function, returning a value to the caller.
  • 'return' suspends the function's state, allowing it to resume execution later.
  • 'yield' immediately terminates the function, returning a value to the caller.
  • 'yield' suspends the function's state, allowing it to resume execution later.
'yield' and 'return' serve different purposes in Python. 'yield' is used in generators to pause execution and later resume it, whereas 'return' terminates the function.

When using nested loops, the break statement will exit the _______ loop.

  • Current
  • Inner
  • Outer
  • Parent
The 'break' statement in Python is used to exit the innermost loop when used in nested loops. It terminates the loop in which it is placed, hence exiting the 'Inner' loop.

Which keyword is specifically used to terminate a loop prematurely?

  • break
  • exit
  • halt
  • terminate
The break keyword is used to prematurely terminate a loop in Python. When encountered, it exits the loop and continues with the next statement.

Consider a situation where multiple methods in a class can be potentially overloaded. How does Python decide which one to execute?

  • Python chooses the overloaded method with the shortest name.
  • Python executes all overloaded methods simultaneously.
  • Python executes the method defined in the derived class, ignoring overloaded methods in base classes.
  • Python executes the overloaded method based on the arguments passed during the function call.
In Python, method overloading isn't supported in the traditional sense as in some other languages. Python decides which method to execute based on the arguments passed during the function call. It doesn't execute all overloaded methods simultaneously, and it doesn't consider the method name or the class hierarchy.

For an infinite loop using the while construct, the typical condition used is while _______:

  • 1
  • FALSE
  • None of the above
  • TRUE
For creating an infinite loop using the 'while' construct, the typical condition used is 'while True:'. This condition ensures that the loop will continue running indefinitely since 'True' is always evaluated as true. Infinite loops can be useful in certain scenarios, such as running a server or a program that should run continuously.

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()'.

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.