Lesson Overview and Plan

Welcome! Today's mission involves learning about constructors in Python, specifically focusing on the __init__ method. Constructors define the initial state of Python objects, much in the same way that a spacecraft is prepared for launch. In this lesson, we will learn about constructors, create them using the __init__ method, work with multiple objects, and understand their importance.

Introduction to Constructors

Put simply, a constructor prepares an object when it is initially created. Python works with constructors through the __init__ method.

The __init__ method sets the initialization process in motion for Python objects. You can visualize this with the following Spaceship class:

In this class, __init__ establishes destination and speed for a Spaceship, which doesn't require any additional input.

Creating a Constructor with __init__

The __init__ method is called automatically when an object is constructed. Upon invocation, refers to the newly created object:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal