Classes may also be related to each other through a mechanism called inheritance. When one class inherits from another, it inherits all the state and behavior of the original class, and then has the opportunity to define additional new state and behavior.
The Sierpinski triangle is an interesting mathematical object (a fractal, like the Mandelbrot set) that is constructed by repeatedly removing the middle from a solid triangle.
Listing 25.1: Sierpinski Triangle
1 # sierpinski.py
3 from turtle import Turtle, setworldcoordinates, exitonclick
5 class SierpinskiTriangle(Turtle):
6 size = 2
7 def __init__(self, n, x, y):
8 Turtle.__init__(self, visible=False)
9 self.n = n