If you want to type hint a variable that can be either an integer or a float, you would use Union[int, _______].

  • Any
  • float
  • number
  • real
To type hint a variable that can be either an integer or a float, you would use 'Union[int, float]'. The 'Union' type hint allows specifying multiple acceptable types.

If a derived class does not have its constructor, which constructor gets called when an object of the derived class is instantiated?

  • Base class constructor
  • Derived class constructor
  • Python automatically creates a default constructor for the derived class.
  • There is an error and no constructor is called.
If the derived class does not have its constructor, the base class constructor is called when an object of the derived class is instantiated. It's important to remember that if the base class constructor has parameters, you must explicitly call it in the derived class's constructor using super().init() to ensure proper initialization.

You are debugging a program that should print numbers from 1 to 10, but it's getting stuck and printing the same number indefinitely. What could be a possible reason?

  • Incorrect Print Statement
  • Infinite Loop
  • Memory Overflow
  • Syntax Error
The program printing the same number indefinitely suggests an infinite loop. Infinite loops can occur when the loop condition is not being updated correctly, leading to the program getting stuck on the same step. This can be due to a logical error in the loop's condition or the loop variable not being updated properly.

What is method overloading in Python?

  • Automatically resolves ambiguity
  • Defining multiple methods
  • Python doesn't support it
  • Using the '@overload' decorator
Method overloading, as seen in some other languages, is not directly supported in Python. Python resolves method calls based on the arguments passed.

You have a function that takes three parameters, but sometimes you need to pass more arguments. Which technique allows for this?

  • Using default arguments
  • Using keyword arguments (kwargs)
  • Using optional parameters
  • Using variable-length argument lists (args)
To pass more arguments than expected, you can use variable-length argument lists (args), allowing for a flexible number of additional arguments.

In a Python codebase, you see that a child class is trying to modify an attribute with two leading underscores from a parent class but encounters an error. What's the likely cause?

  • Python does not allow modifying attributes from child classes.
  • The attribute is marked as a protected attribute and can only be accessed within the parent class.
  • The attribute with double underscores is treated as a name mangling name, and it's not directly accessible from child classes.
  • The child class does not have proper inheritance from the parent class.
In Python, an attribute with double underscores (e.g., __attribute) is treated as a name-mangling name. It's not directly accessible from child classes to prevent accidental overwriting.

_______ is the built-in Python exception for an error in the program logic.

  • RuntimeError
  • SyntaxError
  • TypeError
  • ValueError
SyntaxError is the built-in Python exception that occurs when there is an error in the program's syntax or structure.

In which file mode can you read from and write to a file simultaneously?

  • append-update mode
  • read-append mode
  • read-write mode
  • read-write-append mode
You can read from and write to a file simultaneously in 'read-write-append mode' ('r+'). It allows both reading and writing operations on the file.

The while loop continues execution as long as the test expression remains _______.

  • FALSE
  • Non-zero
  • TRUE
  • True or False
The while loop continues execution as long as the test expression remains True. It repeatedly executes a block of code as long as the specified condition evaluates to True.

In Python, a class member prefixed with two underscores, such as __memberName, is conventionally considered as _______.

  • Private Member
  • Public Member
  • Protected Member
  • Hidden Member
In Python, a class member prefixed with two underscores (e.g., __memberName) is conventionally considered a "private" member. It's a way to indicate that the member should not be accessed directly from outside the class.