ACTIVITY 41 / 50
Try as many times as you needSet up a new object
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 = colorDefine 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
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль