In Python, to execute a block of code when a condition is false, you use the ______ statement.

  • elif
  • else if
  • else when
  • otherwise
In Python, to execute a block of code when a condition is false, you use the 'else' statement. The 'else' block is executed when the preceding 'if' condition evaluates to False, providing an alternative code path.

Which of the following best describes the behavior of the continue statement inside a loop?

  • It exits the loop and resumes execution from the beginning of the loop.
  • It is used to define an exception handling block within the loop.
  • It skips the rest of the current iteration and proceeds to the next iteration of the loop.
  • It terminates the loop entirely.
The continue statement, when encountered, skips the current iteration of a loop and proceeds to the next iteration. It does not exit the loop. This is often used to skip specific elements or conditions within a loop without terminating it.

Consider nested if statements in Python. What could be a potential drawback of having many levels of nested conditions?

  • Decreased code complexity
  • Improved readability
  • Increased maintainability
  • Increased potential for logic errors
Having many levels of nested conditions can increase the potential for logic errors because it becomes harder to track and debug the code, leading to increased complexity and decreased maintainability.

How does Python interpret the following line: # This is a comment?

  • It's a multiline string
  • It's a syntax error
  • It's executed as code
  • It's treated as a comment
In Python, lines starting with '#' are considered comments. They are ignored by the interpreter and serve as documentation for human readers.

If you want to make a class attribute read-only, you'd typically use the _______ decorator.

  • @readonly
  • @property
  • @readonly.setter
  • @attribute.getter
To make a class attribute read-only, you typically use the @property decorator. This decorator allows you to define a method that can be used to access the attribute but not set it directly.

When raising a custom exception, the _______ method gets called to display the error message.

  • display_error
  • raise_message
  • str()
  • str()
When raising a custom exception, the __str__() method of the exception class gets called automatically to generate the error message. You can override this method to customize the error message displayed when the exception is raised.

For a single if condition, if you want to run one block for a true condition and another block for a false condition, you need the if along with the ______ block.

  • elif
  • else
  • else if
  • otherwise
For a single if condition, if you want to run one block for a true condition and another block for a false condition, you need the 'if' along with the 'else' block. The 'else' block contains the code that is executed when the 'if' condition evaluates to False.

How did Python get its name?

  • Named after a TV show
  • Named after a computer game
  • Named after a mathematician
  • Named after a snake
Python is named after the famous British comedy group Monty Python, not the snake. Guido van Rossum, Python's creator, was a fan of the group.

Which of the following is true regarding the mutability of tuples in Python?

  • Tuples are immutable
  • Tuples are mutable
  • Tuples can be partially mutable
  • Tuples can be resized
Tuples are immutable in Python, meaning their elements cannot be changed after creation. However, they can contain mutable objects like lists.

You're building a logging system that reads logs from a CSV file and converts them into JSON format. What's the best approach to handle a very large CSV file to ensure efficient memory usage?

  • Read the CSV file line by line and convert each line.
  • Read the entire CSV file into memory and then convert it.
  • Use a database to store CSV data and then convert it to JSON.
  • Use the 'with' statement to open the file and process it efficiently.
The best approach for handling large CSV files is to read them line by line. Reading the entire file into memory can lead to memory issues, while processing line by line ensures efficient memory usage.