What is the primary difference between method overloading and method overriding in Python?

  • Method overloading allows a method to have the same name but different parameters in the same class.
  • Method overloading is for constructors, while method overriding is for regular methods.
  • Method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.
  • There is no difference; these terms are used interchangeably in Python.
The primary difference between method overloading and method overriding in Python is that method overloading involves defining multiple methods with the same name but different parameters in the same class, while method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.

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.

To compile a Python script to bytecode without executing it, the command used is python -_______ .

  • c
  • compile
  • noexec
  • pyc
To compile a Python script to bytecode without executing it, the command used is python -m py_compile . The -m flag is used to invoke the py_compile module, and is the Python script you want to compile.

In a series of if, elif, and else, how many times can elif appear?

  • Any number
  • Multiple times
  • Never
  • Only once
In Python, you can have multiple elif branches in a series of if, elif, and else statements. It allows you to test multiple conditions before falling back to the else block if none of the conditions are met.

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.