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, ...
Get A Concise Introduction to Programming in Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.