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.

The process of converting source code into bytecode, which is then executed by the Python interpreter, is called _______.

  • Compilation
  • Compilation
  • Execution
  • Interpretation
Python uses interpretation, not compilation, to execute code. The process is called interpretation, not compilation.

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.

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's the primary benefit of using tuples as keys in dictionaries over lists?

  • Tuples are faster to access.
  • Tuples are immutable.
  • Tuples are more memory-efficient.
  • Tuples guarantee order.
The primary benefit of using tuples as keys in dictionaries is that tuples are immutable, while lists are not. This immutability ensures that the keys won't change, making tuples suitable for use as dictionary keys. Lists can't be used as keys because they can change.

_______ is a built-in Python function that dynamically loads a module into the current namespace.

  • import
  • include
  • load
  • require
The import statement is used to dynamically load a module into the current Python namespace. It allows you to access functions, classes, and variables defined in the imported module. This dynamic loading is crucial for code modularity and reusability, enabling you to use code from different modules in your Python programs.