__init__

The dunder method Python calls to set up a newly created instance, receiving the arguments passed to the class.

In more detail

It normally stores those arguments as instance attributes on self. It must not return a value; the new instance is what calling the class gives back.

Example

def __init__(self, name):
    self.name = name

Related terms

Taught in

References

Certification courses