If a member is named _memberName in a Python class, it is conventionally considered to be _______.

  • Private
  • Protected
  • Public
  • Static
If a member in a Python class is named with a single underscore prefix (e.g., _memberName), it is conventionally considered a private member.

How can you add multiple key-value pairs to an existing dictionary?

  • Using a for loop to iterate over a list of tuples, where each tuple contains a key-value pair, and using the update() method to add them to the dictionary.
  • By using the add() method and providing a list of key-value pairs.
  • Using the extend() method to append a list of key-value pairs to the dictionary.
  • By directly assigning a list of key-value pairs to the dictionary variable.
You can add multiple key-value pairs to an existing dictionary by using a for loop to iterate over a list of tuples, where each tuple contains a key-value pair, and then using the update() method to add them to the dictionary. The other options mentioned (add(), extend(), and direct assignment) are not standard methods for adding multiple key-value pairs to a dictionary.

During data analysis, you are given a set of IDs from two different sources. You need to find IDs that are either in the first set or the second set but not in both. Which set operation will you apply?

  • Difference
  • Intersection
  • Symmetric Difference
  • Union
To find IDs that are in either the first set or the second set but not in both, you would apply the "Symmetric Difference" set operation. This will give you elements that are exclusive to each set.

The _______ attribute of an exception object returns a tuple containing an exception type, a value, and a traceback object.

  • args
  • error_details
  • exception_info
  • traceback_info
The 'args' attribute of an exception object returns a tuple containing information about the exception, including the exception type, a value (exception message), and additional details if any. This information is useful for debugging and error handling.

In what scenario might using a defaultdict be more appropriate than using a standard dictionary?

  • When you need constant-time lookups
  • When you need to handle missing keys more gracefully
  • When you need to sort the dictionary
  • When you want to save memory space
A defaultdict is useful when you want to handle missing keys more gracefully by providing a default value or factory function. It can simplify code that deals with non-existent keys.

The process of giving an extended meaning to operators for user-defined data types is called _______.

  • Operator Customization
  • Operator Definition
  • Operator Extension
  • Operator Overloading
The process of giving an extended meaning to operators for user-defined data types is called Operator Overloading. It allows you to define how operators behave with custom objects.

Which of the following tools is used to create isolated Python environments?

  • Anaconda
  • PyDist
  • PyEnv
  • Virtualenv
'Virtualenv' is a tool used to create isolated Python environments. It allows you to work on different projects with their own dependencies without conflicts.

In what scenario is the __name__ attribute of a module set to its own module name instead of "__main__"?

  • When the module is a built-in module
  • When the module is defined in Python 2.x
  • When the module is imported as a library
  • When the module is the main program
The __name__ attribute of a module is set to its own module name when it's imported as a library by another module. It's set to "__main__" when the module is the main program being executed.

Which of the following will catch all exceptions in Python?

  • try/except
  • try/except: AllExceptions
  • try/except: BaseException
  • try/except: Exception
To catch all exceptions in Python, you can use 'try/except' with 'BaseException' as the exception type, which is the base class for all exceptions.

When creating a custom exception, it should typically inherit from _______.

  • BaseException
  • Error
  • Exception
  • RuntimeError
When creating a custom exception in Python, it is advisable to inherit from the 'Exception' class, which is the base class for all built-in exceptions. This allows your custom exception to be treated like a standard exception.