What happens if the base class method is private, and you try to override it in a derived class?

  • Compilation error
  • The base class method is called
  • The derived class method is overridden
  • The derived class method is private
If the base class method is private, it cannot be overridden in the derived class. Attempting to do so will result in a compilation error, as private methods are not accessible outside the class.

Which of the following decorators is used to define a setter method for a property in Python?

  • @getter
  • @property
  • @setter
  • @setter and @getter
The @property decorator is used to define a getter method for a property. To define a setter, you would use @.setter.

Which built-in function in Python can be used to get the data type of an object?

  • dtype()
  • type()
  • typeof()
  • typeofobject()
The type() function is used to determine the data type of an object in Python. It returns a type object, which represents the data type of the given object.

If you have a function named fun inside a module named mod, how can you import it directly?

  • from mod import fun
  • fun(mod)
  • import fun from mod
  • include mod.fun
To import a specific function from a module, you use the syntax from mod import fun. This allows you to use fun directly in your code.

A program is intended to print all even numbers between 1 to 10 but instead, it prints all numbers between 1 to 10. What control structure might be missing or misused?

  • Conditional Statement
  • For Loop
  • Range Function
  • While Loop
If a program is printing all numbers between 1 to 10 instead of just even numbers, a conditional statement might be missing or misused. Conditional statements are used to specify different actions based on certain conditions, and they are essential for filtering and printing even numbers in this case.

You have a program that checks for a user's age to determine the price of a movie ticket. How would you structure the conditional statements to determine if a user gets a discount based on their age?

  • if age < 10 or age > 65:
  • if age == 10 or age == 65:
  • if age > 10 and age < 65:
  • if age >= 10 and age <= 65:
To determine if a user gets a discount based on age, you should use 'if' statements with logical OR operators. This way, you can identify both children under 10 and seniors above 65 who are eligible for a discount.

How can you profile a Python script to analyze the time spent in each function call?

  • Use the cProfile module to profile the script, which provides detailed information about the time spent in each function call.
  • Use the inspect module to analyze the source code of the script.
  • Use the timeit module to measure the execution time of the entire script.
  • Use the trace module to trace the execution of the script line by line.
Profiling a Python script to analyze function call times involves using the cProfile module, which provides detailed statistics on function calls, including time spent in each function.

How can you reload a module that has been modified after it was initially imported?

  • importlib.reload(module)
  • module.reload()
  • module.reload_module()
  • reload(module)
To reload a module in Python, you can use the importlib.reload(module) function from the importlib library. This function reloads the specified module, allowing you to access any changes made to it.

How can you remove all items from a Python set?

  • set.clear()
  • set.delete_all()
  • set.discard_all()
  • set.remove_all()
To remove all items from a Python set, you can use the clear() method. This method clears all elements from the set, leaving it empty. The other options do not exist as methods for removing all items from a set.

How can you run a specific test method from a test case in unittest?

  • Specify the method name as an argument to unittest.main()
  • Use the python -m unittest command
  • Use the run method of the test case
  • Use the run_test function
To run a specific test method from a test case in unittest, you can use the run method of the test case class and specify the method name as an argument to it. The other options are not the standard way to run specific test methods in unittest.