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.

When sorting a list with the sort() method, using the _______ argument can allow for custom sorting behaviors.

  • custom
  • custom_sort
  • key
  • sort_by
When sorting a list using the sort() method, you can provide a key argument to specify a custom sorting behavior. This allows you to sort based on specific criteria or functions.

To create a tuple with a single item, you need to add a _______ after the item.

  • Colon
  • Comma
  • Period
  • Semicolon
To create a tuple with a single item, you need to add a comma after the item. For example, my_tuple = (42,). A trailing comma distinguishes a single-item tuple from an expression in parentheses.

You are building a recommendation engine and have a set of products bought by User A and another set for User B. To recommend new products to User A based on User B's purchases, which set operation would you use considering you don't want to recommend products User A has already bought?

  • Difference
  • Intersection
  • Symmetric Difference
  • Union
To recommend new products to User A based on User B's purchases while avoiding duplicates, you would use the "Difference" set operation. This will provide products in User B's set that are not in User A's set.

The true mechanism behind private attributes in Python is a feature called _______.

  • abstraction
  • data hiding
  • encapsulation
  • name mangling
Python uses a technique called "name mangling" to make attributes private by adding a prefix to their names.

Which of the following can be used to import only a specific function or class from a module?

  • from module import function
  • import function from module
  • import module
  • import module.function
You can use 'from module import function' to import only a specific function or class from a module in Python.

If d is a dictionary, the method d.______() will return a list of all the values in the dictionary.

  • extract_values
  • get_values
  • list_values
  • values
The values() method in Python returns a view object that displays a list of all the values in the dictionary. You can convert this view to a list if needed.

_______ 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.

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.

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.

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.

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.