If the class constructor is declared in the following way:
Which one of the assignments is invalid?
Which one of the assignments is invalid?
class Class: def __init__(self, val=0): pass
- object = Class(1)
- object = Class()
- object = Class(None)
- object = Class(1, 2)
Explanation: An attempt to create an object of class Class using the assignment object = Class(1, 2) will raise a TypeError exception, because a maximum of two arguments are accepted by the __init__ declaration, not three arguments (self, 1, and 2).
More Questions: Python Essentials 2 (PE2) Course Final Test
Please login or Register to submit your answer