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.

Python files have the extension _______.

  • .code
  • .py
  • .script
  • .txt
Python files typically have the extension '.py'. It's the standard file extension for Python source code files.

What will be the result of the comparison 5 != 6 in Python?

  • 1
  • Error
  • FALSE
  • TRUE
The expression 5 != 6 compares whether 5 is not equal to 6. Since this is true, the result is 'True.'

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.

In which scenario would the @classmethod decorator be more appropriate than @staticmethod?

  • When the method doesn't require access to class-specific data
  • When the method is called on an instance
  • When the method needs no arguments
  • When the method requires access to class-specific data
The @classmethod decorator is more appropriate than @staticmethod when the method needs access to class-specific data, such as class attributes or methods. @staticmethod is used when the method doesn't rely on any class-specific data.

To check if a dictionary d has a key "name," you can use the expression "name" in _______.

  • d
  • d.has_key()
  • d.has_name()
  • d.keys()
To check if a dictionary has a specific key, you can use the in keyword followed by the dictionary's keys() method. For example, if "name" in d.keys(): will check if the key "name" exists in the dictionary d.

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.