If you want to check multiple conditions and execute a block when the first true condition is encountered, you use the ______ keyword after the initial if statement.

  • elif
  • elseif
  • or else
  • or if
To check multiple conditions and execute a block when the first true condition is encountered, you use the 'elif' keyword. 'elif' is short for 'else if' and allows you to chain multiple conditions together, with the block associated with the first true condition being executed.

Imagine you are developing a game and you have a Player class. Every player has a unique ID and a score. Which method would be best suited to fetch the highest score across all players without needing an instance of the player class?

  • classmethod
  • instance method
  • property
  • staticmethod
To fetch the highest score across all players without needing an instance of the player class, you should use a staticmethod. Static methods are called on the class itself and don't require an instance, making them suitable for tasks that don't involve instance-specific data.

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.

Imagine you have a Circle class where you want the radius to always be non-negative. Which approach would you use to ensure this while still allowing direct assignment like circle.radius = 5?

  • Making the radius attribute private and providing a public method to set it.
  • Not allowing direct assignment to the radius attribute.
  • Using a property with a setter method that checks and enforces the non-negativity of the radius.
  • Using the @property decorator without a setter method.
You would use a property with a setter method to validate the radius and ensure it's non-negative while still allowing direct assignment. The setter method can perform the check.