Exam PCAP All QuestionsBrowse all questions from this exam
Question 100

What is true about Python class constructors? (Choose two.)

    Correct Answer: C, D

    In Python, a class constructor is defined by the method __init__. This method initializes the object's attributes and is essential in creating class instances. Hence, the statement that the constructor is a method named __init__ is true. Additionally, the constructor must have at least one parameter, which is typically 'self.' This parameter refers to the instance being created, making it mandatory. Therefore, the constructor must include at least 'self' as a parameter, fulfilling the requirement of having at least one parameter.

Discussion
macxszOptions: CD

C. the constructor is a method named __init__ D. the constructor must have at least one parameter <<<< at least it should have "self" parameter