For an infinite loop using the while construct, the typical condition used is while _______:

  • 1
  • FALSE
  • None of the above
  • TRUE
For creating an infinite loop using the 'while' construct, the typical condition used is 'while True:'. This condition ensures that the loop will continue running indefinitely since 'True' is always evaluated as true. Infinite loops can be useful in certain scenarios, such as running a server or a program that should run continuously.

Consider a situation where multiple methods in a class can be potentially overloaded. How does Python decide which one to execute?

  • Python chooses the overloaded method with the shortest name.
  • Python executes all overloaded methods simultaneously.
  • Python executes the method defined in the derived class, ignoring overloaded methods in base classes.
  • Python executes the overloaded method based on the arguments passed during the function call.
In Python, method overloading isn't supported in the traditional sense as in some other languages. Python decides which method to execute based on the arguments passed during the function call. It doesn't execute all overloaded methods simultaneously, and it doesn't consider the method name or the class hierarchy.

Consider a loop that processes each item in a list. If you want to skip processing for specific items and continue with the next one, which statement would you use?

  • break
  • continue
  • pass
  • skip
To skip processing for specific items in a loop and continue with the next one, you would use the 'continue' statement. It allows you to bypass the current iteration and move on to the next item in the loop.

Which method would you use to get a list of all the keys in a dictionary?

  • d.items()
  • d.keylist()
  • d.keys()
  • d.values()
To get a list of all the keys in a dictionary 'd', you would use the d.keys() method. It returns a list of all the keys present in the dictionary.

The variables that are defined inside a function are referred to as _______ variables.

  • Global
  • Instance
  • Local
  • Non-local
Variables defined inside a function are known as 'local' variables. They are only accessible within that function's scope.

Which of the following is a recommended use case for custom context managers?

  • Basic arithmetic calculations.
  • Closing a file after reading/writing data
  • Sorting a list of integers.
  • Web scraping with BeautifulSoup.
A recommended use case for custom context managers is closing a file after reading or writing data. This ensures proper resource cleanup and prevents resource leaks when dealing with files.

You are writing a nested function, and you want to modify a variable from the outer function. However, you don't want this change to affect the global scope. How can you achieve this?

  • Use the global keyword
  • Use the local keyword
  • Use the nonlocal keyword
  • Use the private keyword
To modify a variable from an outer function without affecting the global scope, use the 'nonlocal' keyword. It allows you to access and modify the variable in the closest outer scope.

Which of the following statements is true about private attributes in a Python class?

  • Private attributes are accessible and modifiable outside the class, just like public attributes.
  • Private attributes are denoted by a double underscore prefix, such as "__private". They can be accessed and modified outside the class.
  • Private attributes are denoted by a single underscore prefix, such as "_private". They are intended for internal use within the class.
  • Private attributes are inaccessible from outside the class, making them more secure.
Private attributes in Python are typically denoted by a single underscore prefix (e.g., "_private"). While they can still be accessed from outside the class, the convention is to treat them as non-public and for internal use.

The _______ file can control which modules are imported when 'from package import *' is invoked.

  • import_rules.txt
  • init.py
  • main.py
  • package_config.ini
The init.py file in a Python package can control which modules are imported when 'from package import *' is used. It allows you to define the package's public interface.

Which keyword is used in Python to create a derived class?

  • baseclass
  • class
  • extends
  • superclass
In Python, the 'class' keyword is used to create both base (parent) classes and derived (child) classes. The derived class is created by inheriting from a base class.