The counterpart to the @property decorator for setting the value of an attribute is _______.

  • @attribute.setter
  • @property.setter
  • @value.setter
  • @set.setter
The counterpart to the @property decorator for setting the value of an attribute is @attribute.setter. It allows you to define a method that sets the value of the corresponding attribute.

What keyword is used to define a function in Python?

  • def
  • define
  • func
  • function
In Python, the keyword used to define a function is 'def.' You start a function definition with 'def,' followed by the function name and its parameters.

Which of the following is not a valid list comprehension?

  • [x for x in range(10)]
  • [(x, x**2) for x in y]
  • [x if x % 2 == 0 else 'odd' for x in range(10)]
  • [x if x > 5 else for x in range(10)]
The fourth option is not a valid list comprehension because it's missing the expression that should follow the else keyword. In list comprehensions, the else part should have an expression to be evaluated when the condition is False. The correct form should be like: [x if x > 5 else for x in range(10)].

When you want a variable to be available both inside and outside a function, you declare it as a _______ variable.

  • Global
  • Instance
  • Local
  • Non-local
To make a variable accessible both inside and outside a function, you declare it as a 'global' variable. It has a global scope.

When using a nested loop inside a list comprehension, the _______ loop should be specified first.

  • Inner
  • Outer
  • Primary
  • Secondary
When using nested loops in list comprehensions, the inner loop should be specified first. This is because the inner loop is executed more frequently and iterates over each element in the inner sequence, while the outer loop iterates over the outer sequence. The inner loop determines how the elements are constructed in the resulting list comprehension.

You have a base class Vehicle and a derived class Car. The base class has a method start(). If you want to add additional functionalities to the start() method specifically for the Car class without affecting the base class, what should you do?

  • Use method overloading to create a new start() method in the Car class
  • Use method overriding to override the start() method in the Car class
  • Use multiple inheritance to inherit from both Vehicle and Car classes and create a new start() method in the Car class
  • Use the super() keyword to extend the start() method in the Car class
In this case, you should use method overriding in the Car class. By using the super() keyword, you can extend the functionality of the start() method specific to the Car class without modifying the base class (Vehicle) method. This approach follows the principle of object-oriented programming and avoids redundancy.

When writing nested if statements, each new condition should be indented under the ______ statement.

  • elif
  • else
  • if
  • while
When writing nested if statements in Python, each new condition should be indented under the 'if' statement to indicate it's a part of that condition's block.

Which of the following symbols is used to define a tuple in Python?

  • ( )
  • < >
  • [ ]
  • { }
In Python, tuples are defined using parentheses ( ). For example, my_tuple = (1, 2, 3) creates a tuple named my_tuple.

Which Python Enhancement Proposal (PEP) introduces the concept of "The Zen of Python"?

  • PEP 20
  • PEP 42
  • PEP 64
  • PEP 8
"The Zen of Python" is introduced in PEP 20. It encapsulates the guiding principles and philosophy of Python's design.

In Python, to create a private attribute in a class, you prefix the attribute name with _______.

  • @private
  • __private
  • _private
  • private:
In Python, a private attribute is created by prefixing the attribute name with a double underscore, like "__private".