← Python from Scratch
Lesson 59 of 78 · 5 XP
Warm-up: your first class warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
A class is a blueprint, and an object is a thing made from the blueprint. Functions inside a class are called methods, and their first parameter is always self:
class Robot:
def hello(self):
return "Beep!"
r = Robot() # made an object from the blueprint
print(r.hello()) # Beep!
Task. Create a class Hero with a method hello() that returns the string I am a hero!.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.