The operator // performs _______ division.

  • Division
  • Float
  • Integer
  • Truncated
The operator '//' performs truncated division. It returns the integer part of the result of division, discarding the decimal part.

Why are tuples generally faster than lists when it comes to iteration?

  • Lists are stored in a linked list structure.
  • Lists have more built-in functions.
  • Tuples are immutable.
  • Tuples use less memory.
Tuples are generally faster for iteration because they are immutable. This immutability means that the interpreter can optimize memory usage and access elements directly, leading to faster iteration.

A method inside a class that does not access or modify class-specific data is often marked as a _______.

  • abstract
  • instance
  • non-static
  • static
A method inside a class that does not access or modify class-specific data is often marked as a static method.

Your application needs to write user data into a file. To ensure data consistency, even if the application crashes during a write operation, what measure would you take?

  • Enable automatic file versioning to track changes and ensure consistency.
  • Use a try-except block to handle crashes and continue writing.
  • Use file locking to prevent other processes from accessing the file during writes.
  • Write data to a temporary file and then replace the original file.
To ensure data consistency, write data to a temporary file first, and then replace the original file. This way, if the application crashes during writing, the original file remains intact.

Which Python function is used to open a file for reading?

  • file_open()
  • open()
  • open_file()
  • read_file()
The 'open()' function in Python is used to open a file for reading. It returns a file object that can be used to read the file's contents.

Which of the following lines will throw an indentation error in Python?

  • if True:
  • print("Hello, world!")
  • print("Python is fun!")
  • print("Python is easy!")
The correct option is 4. It lacks proper indentation, which is essential in Python to define code blocks. An indentation error would occur in this case.

Which method is responsible for cleaning up resources in a context manager?

  • __cleanup__()
  • __close__()
  • __deallocate__()
  • __exit__()
The __exit__() method is responsible for cleaning up resources in a context manager. It's called automatically when exiting the 'with' block, allowing you to release resources or handle exceptions.

Which Python conditional statement allows for the checking of multiple conditions sequentially until one is found to be true?

  • if-elif
  • if-else if
  • switch-case
  • while
In Python, the 'if-elif' (short for "else if") statement allows for checking multiple conditions sequentially until one is found to be true. This is useful for handling multiple exclusive cases.

You have a list of numbers, and you want to compute the cumulative sum of elements. Which looping structure is best suited for this?

  • do-while loop
  • for loop
  • list comprehension
  • while loop
The 'for loop' is best suited for computing the cumulative sum of elements in a list. It allows you to iterate through the list and accumulate the sum of elements as you go, making it an efficient choice for this task.

If a class in Python has a method named _protectedMethod, it's a convention that this method is intended to be _______.

  • internal
  • private
  • protected
  • public
In Python, methods with a single leading underscore like '_protectedMethod' are considered protected, indicating they should be used with caution.