← Reference

Classes: cheat sheet

Objects with turtles · In any playground, open Reference to copy these.

class

A new kind of object. __init__ runs when one is made; self.name = value stores a value in that object.

class Star:
    def __init__(self, x):
        self.speed = 5

s = Star(100)

method

A function inside a class. Call it on one object: star.move(). self is that object.

    def move(self):
        self.turtle.forward(self.speed)