Question 21
What is the purpose of the __str__() method in a Python class?
Option C is correct. __str__() is called by str(object) and print() to return a readable, informal string representation intended for end-users.
What is the purpose of the __str__() method in a Python class?
Option C is correct. __str__() is called by str(object) and print() to return a readable, informal string representation intended for end-users.
What does nonlocal keyword do in Python nested functions?
Option B is correct. nonlocal allows inner functions to modify variables declared in their outer enclosing non-global function scope.
Which Python method removes and returns the last element from a list?
Option A is correct. list.pop() removes and returns the item at the given position (defaulting to the last index -1). remove(x) removes the first item matching value x.
What is a $\lambda function$ in Python?
Option A is correct. A $\lambda function$ is a small, single-expression anonymous function defined using $\lambda arguments$: expression without a formal function name.
In Python, how is single inheritance implemented in a child class definition?
Option E is correct. In Python, inheritance is specified by passing the parent class name in parentheses after the child class name: class Child(Parent):.