You have two sets, one containing all employees who attended a training session and another with employees who completed an online assessment. You want to find out who attended the training but did not complete the assessment. Which set operation would help?

  • Difference
  • Intersection
  • Symmetric Difference
  • Union
To find employees who attended training but did not complete the assessment, you would use the "Difference" set operation. This will give you the elements that are in the first set but not in the second.

You notice a script is taking more memory than expected even after finishing its tasks. You suspect some objects aren't being garbage collected. How can you explicitly attempt to clean them up?

  • clear_memory()
  • del objects
  • gc.collect()
  • mem_cleanup(objects)
To explicitly attempt to clean up objects and free memory, you can use gc.collect(). This function is part of Python's gc (garbage collection) module and triggers the garbage collection process, which reclaims memory occupied by unreachable objects.

In a custom Fraction class, if you want to compare two fractions using the == operator, which method should be overloaded?

  • Overload the addition operator (+) in the Fraction class.
  • Overload the division operator (/) in the Fraction class.
  • Overload the equality operator (==) in the Fraction class.
  • Overload the multiplication operator (*) in the Fraction class.
To compare two fractions using the == operator, you should overload the equality operator (==) in the Fraction class to define how fractions should be compared for equality.

How do you access the first item in a tuple named my_tuple?

  • my_tuple(0)
  • my_tuple<0>
  • my_tuple[0]
  • my_tuple{0}
To access the first item in a tuple, you use square brackets and specify the index. For example, my_tuple[0] retrieves the first item.

When trying to execute an expression like obj1 * obj2 for custom objects, Python internally calls _______.

  • __mul__
  • __mult__
  • __multiply__
  • __product__
When you attempt to execute an expression like obj1 * obj2 for custom objects, Python internally calls the __mul__ method. Implementing this method allows you to define how the multiplication operation behaves for your objects.

How can you remove an element from a set without raising an error if the element doesn't exist?

  • delete()
  • discard()
  • pop()
  • remove()
You can use the discard() method to remove an element from a set without raising an error if the element doesn't exist in the set. It's a safe removal method.

How does the method resolution order (MRO) in Python impact method overloading in the context of inheritance?

  • It allows Python to call overloaded methods based on the order they are defined in the class.
  • It doesn't impact method overloading; Python uses the last defined method with the same name.
  • MRO affects method overloading by considering the class hierarchy and the order of base classes.
  • MRO doesn't matter; Python uses the method with the same name in the most derived class.
The MRO in Python determines the order in which methods are searched for in class hierarchies. When methods are overloaded, the MRO helps Python find the appropriate method by considering the class hierarchy and the order of base classes. The method is then called based on the MRO.

In a multi-level inheritance scenario, you notice that the derived class is not behaving as expected when a method is called. You suspect that there's confusion with method overriding from multiple base classes. How might you diagnose this?

  • Use the 'dir()' function to list all methods available in the derived class
  • Use the 'help()' function to view the documentation of the methods in the derived class
  • Use the 'isinstance()' function to check the object's class hierarchy and method resolution order (MRO)
  • Use the 'super()' keyword to explicitly specify the base class from which the method should be inherited
To diagnose issues related to method overriding in a multi-level inheritance scenario, you can use the 'isinstance()' function. It helps you check the object's class hierarchy and method resolution order (MRO). This allows you to identify which base class method is being called and whether there's any confusion with method names in the inheritance hierarchy.

The contextlib module provides a utility called _______ to create context managers using generator functions.

  • @contextgen()
  • @contextmanager
  • @gen_manager
  • @generator_context
The 'contextlib' module provides a utility called '@contextmanager' that is used as a decorator to create context managers using generator functions. It simplifies context manager creation.

In which scenario might you use the built-in import() function instead of a regular import statement?

  • When you want to import a module as a built-in Python module.
  • When you want to import a module dynamically based on user input or conditions.
  • When you want to import a module from an external directory.
  • When you want to improve code readability by avoiding long import statements.
The 'import()' function is used to import modules dynamically at runtime, often when the module names are determined by user input or other dynamic factors.