How would you define a class attribute that should not be overridden by subclasses?

  • Declare it as a constant
  • Declare it as a static method
  • Prefix it with an underscore (_)
  • Use the @final decorator
To define a class attribute that should not be overridden by subclasses, prefix it with an underscore (_). While Python doesn't enforce strict encapsulation, this convention signals to other programmers that the attribute should not be modified.

The _______ decorator in a class is used to turn a method into a class-specific method.

  • @classmethod
  • @classmethodmethod
  • @instancemethod
  • @staticmethod
The '@staticmethod' decorator in a class is used to turn a method into a class-specific method. Class-specific methods do not depend on instance-specific data and can be called on the class itself, without creating an instance.

What method is used to add a single element to a set in Python?

  • add()
  • append()
  • insert()
  • update()
The add() method is used to add a single element to a set in Python. It takes one argument, the element you want to add, and modifies the set in place.

How do you execute a block of code only if multiple conditions are all true in Python?

  • Using the 'and' operator
  • Using the 'if' operator
  • Using the 'not' operator
  • Using the 'or' operator
To execute a block of code only if multiple conditions are all true in Python, you use the 'and' operator. It checks if all the specified conditions are true before executing the associated code block.

How does Python enforce the private access modifier for class members?

  • By defining a 'private' keyword
  • By enclosing members in curly braces {}
  • By prefixing with an underscore (_)
  • By using the 'private' keyword
In Python, private access to class members is conventionally enforced by prefixing their names with an underscore (_). While this doesn't make them entirely inaccessible, it signals to other developers that these members should be treated as private and not accessed directly. It's a convention, not a strict enforcement, and it's part of Python's "we are all consenting adults here" philosophy.

Consider a scenario where you need to check if neither 'a' nor 'b' are true in Python. Which of the following operators would you primarily use?

  • a and b
  • a or b
  • not (a or b)
  • not a and not b
To check if neither 'a' nor 'b' are true, you would use the 'not' operator before both 'a' and 'b'. The expression 'not a and not b' ensures that both 'a' and 'b' are not true.

The philosophy of Python is summarized in a document referred to as?

  • PEP Manifesto
  • Python Manifesto
  • Pythonic Principles
  • Zen of Python
The philosophy of Python is famously summarized in the "Zen of Python" (PEP 20). It's a collection of guiding aphorisms for writing computer programs in Python, providing insights into the design principles and philosophy behind the language.

The method _______ is automatically invoked when an attribute's value is retrieved.

  • call
  • get
  • init
  • str
In Python, the __get__ method is automatically invoked when an attribute's value is retrieved using dot notation.

What is the result of the intersection operation between two sets?

  • A set containing all elements common to both sets
  • A set containing all elements in either set
  • A set containing elements unique to the first set
  • An empty set
The intersection operation between two sets in Python returns a new set containing all elements that are common to both sets. If there are no common elements, it returns an empty set.

Which built-in Python module provides mathematical functions?

  • calculations
  • math
  • mathematics
  • numbers
The 'math' module is a built-in Python module that provides a wide range of mathematical functions, such as trigonometric, logarithmic, and exponential functions.

In scenarios where JSON data keys are not simple strings, the json module's _______ argument can be utilized to handle non-string keys.

  • ensure_ascii
  • indent
  • key_transform
  • sort_keys
In scenarios where JSON data keys are not simple strings, the key_transform argument of the json module can be utilized to handle non-string keys by providing a custom function for key transformation.

You have a list of numbers and you want to compute the sum of all positive numbers only. Which control structure can be most beneficial to achieve this?

  • Conditional Statement
  • For Loop
  • List Comprehension
  • While Loop
To compute the sum of all positive numbers in a list, a conditional statement can be most beneficial. You can iterate through the list of numbers and use a conditional statement to check if each number is positive before adding it to the sum. This allows you to selectively sum the positive numbers in the list.