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