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.

To create a module in Python, you need to write your functions, classes, and variables in a _______ file.

  • .module
  • .pack
  • .py
  • .txt
To create a module in Python, you need to write your functions, classes, and variables in a '.py' file, which is a Python source code file.

Which of the following is a modulus operator in Python?

  • %
  • &
  • *
  • ~
The '%' symbol in Python is the modulus operator. It returns the remainder when the first operand is divided by the second operand. For example, 10 % 3 returns 1 because 10 divided by 3 leaves a remainder of 1.

What happens when a function doesn't have a return statement?

  • It raises an error
  • It returns 0
  • It returns None
  • It returns a blank string
When a function lacks a return statement, it automatically returns None. This indicates that the function doesn't return a specific value.

Which of the following tuple methods returns the number of times a specified value appears in the tuple?

  • count()
  • find()
  • index()
  • length()
The count() method is used to determine how many times a specified value appears in a tuple. It's a useful tool for counting occurrences of elements in tuples.

What is the primary difference between a class attribute and an instance attribute in Python?

  • Class attributes are private, while instance attributes are public.
  • Class attributes are shared among all instances of a class, while instance attributes are specific to each instance.
  • Class attributes are specific to each instance, while instance attributes are shared among all instances of a class.
  • Class attributes can only be accessed within the class itself.
The primary difference is that class attributes are shared among all instances of a class, whereas instance attributes are specific to each instance. This affects how data is stored and accessed in Python classes.

Which of the following syntaxes is used to define an empty dictionary in Python?

  • empty_dict = ()
  • empty_dict = []
  • empty_dict = {}
  • empty_dict = {}{}
The correct syntax to define an empty dictionary in Python is 'empty_dict = {}'. An empty dictionary consists of a pair of curly braces with nothing inside.

Which of the following best describes the difference between break and continue in Python loops?

  • 'break' and 'continue' are functionally equivalent.
  • 'break' and 'continue' are used for the same purpose.
  • 'break' continues the loop, 'continue' ends the loop entirely.
  • 'break' ends the loop entirely, 'continue' skips the current iteration and continues with the next.
In Python, the 'break' statement is used to exit the current loop entirely, while 'continue' skips the current iteration and proceeds to the next iteration.

Python's reference implementation is known as _______.

  • CPython
  • PyInterpreter
  • PyRef
  • Pythonic
Python's reference implementation is known as CPython. It is the default and most widely used implementation of Python. Understanding this helps differentiate it from other implementations like Jython or IronPython.