Мой профиль
ACTIVITY 41 / 50

Set up a new object

Try as many times as you need

Let’s understand

The __init__ method runs when an instance is created. self refers to that particular object. self.name = name saves the supplied name in it. __init__ needs two underscores on each side.

Listen to the explanation

Example

class Cup:
    def __init__(self, color):
        self.color = color
YOUR MISSION

Define Robot with __init__(self, name) to save its name. Create Robot("Nova") and print its name.

I need a hint

Inside __init__, use self.name = name.

How to find an error
  1. Read the last line of the error message.
  2. Find the indicated line. Check quotes, parentheses and indentation.
  3. Change one thing and run again.

main.py

4 spaces

Your draft stays in this browser.

Result

Python
Your program’s output will appear here. Click Run.