In a program processing a list of numbers, the objective is to print all numbers until a negative number is encountered. Which control statement would be apt for this task?

  • break
  • for
  • if
  • while
A while loop is apt for this task because it allows you to repeatedly check if the current number is negative and, if not, print it. When a negative number is encountered, the loop terminates, ensuring only non-negative numbers are printed.

In Python, the _______ method is used to overload the + operator.

  • __add__
  • __init__
  • __main__
  • __str__
In Python, the __add__ method is used to overload the + operator for user-defined classes. This method is called when the "+" operator is applied to objects of the class.

The _______ operator returns True if the value on its left is less than the one on its right.

  • Greater than (>)
  • Greater than or equal to (>=)
  • Less than (<)
  • Less than or equal to (<=)
The 'Less than' operator returns True if the value on its left is less than the one on its right.

To execute a Python script, which of the following commands can be used?

  • execute script.py
  • python script.py
  • run script.py
  • start script.py
To execute a Python script, you can use the command python script.py. This command runs the Python interpreter and executes the script specified after python. It's the standard way to execute Python scripts from the command line or terminal.

What is the result of the operation True or False and True?

  • Error
  • FALSE
  • TRUE
  • True and False is not allowed.
The operation 'True or False and True' will result in an error because 'and' has higher precedence than 'or,' and 'and' is trying to combine a Boolean ('False') with a non-Boolean ('True').

What is the maximum length of an identifier (name of a variable, function, etc.) in Python?

  • 63 characters
  • 79 characters
  • 99 characters
  • No fixed limit
In Python, the maximum length of an identifier (variable name, function name, etc.) is 79 characters. However, it's good practice to keep identifiers concise and meaningful.

Unlike lists, tuples are _______ in Python, meaning they cannot be modified after they are created.

  • Dynamic
  • Immutable
  • Mutable
  • Static
Tuples in Python are immutable, which means their elements cannot be changed or modified after the tuple is created.

You're working on a project where a derived class Laptop inherits from two base classes: Computer and PortableDevice. Both base classes have a method named power_on(). If you call power_on() from a Laptop object without any specifications, which method will be invoked?

  • An error will occur due to ambiguity in method names in the multiple inheritance scenario
  • The power_on() method of the Computer class will be invoked
  • The power_on() method of the Laptop class will be invoked
  • The power_on() method of the PortableDevice class will be invoked
In the case of multiple inheritance, if two base classes have a method with the same name, the method of the first base class listed in the inheritance declaration is invoked. In this scenario, calling power_on() from a Laptop object without specifications will invoke the power_on() method of the Computer class.

Who is the creator of Python?

  • Dennis Ritchie
  • Guido van Rossum
  • James Gosling
  • Larry Wall
Python was created by Guido van Rossum in the late 1980s and was first released in 1991.

_______ is an environment where you can write and execute Python commands one-by-one.

  • Compiler
  • Debugger
  • IDE
  • REPL
A REPL (Read-Eval-Print Loop) is an interactive environment where you can input and execute Python commands interactively.