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.

You are designing a Vector class to represent 2D vectors, and you want to add two vectors using the + operator. How would you implement this?

  • Create a new class, VectorAdder, to handle vector addition.
  • Implement a separate function, add_vectors(), for adding vectors.
  • Overload the + operator in the Vector class, so it combines the x and y components of the vectors.
  • Overload the += operator for the Vector class to support in-place addition of vectors.
The correct approach is to overload the + operator in the Vector class, allowing for a natural syntax for vector addition. This is a common operator overloading scenario.

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.

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.

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.