Practice mode Python

What is the role of the __init__ method in a Python class?

Correct answer C. It initialises a newly created instance, typically setting its attributes

Explanation

__init__ is called automatically after an instance has been created, with arguments passed to the class call, and is used to set up initial state such as self.name = name. Creating the object is done by __new__, and __init__ must return None. Clean-up near destruction is __del__.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.