Welcome to “50 Examples for Teaching Python”.

My goal was to collect interesting short examples of Python programs, examples that tackle a real-world problem and exercise various features of the Python language. I envision this collection as being useful to teachers of Python who want novel examples that will interest their students, and possibly to teachers of mathematics or science who want to apply Python programming to make their subject more concrete and interactive.

Readers may also enjoy dipping into the book to learn about a particular algorithm or technique, and can use the references to pursue further reading on topics that especially interest them.

Python version

All of the examples in the book were written using Python 3, and tested using Python 3.2.1. You can download a copy of Python 3 from <>; use the latest version available.

This book is not a Python tutorial and doesn’t try to introduce features of the language, so readers should either be familiar with Python or have a tutorial available. Classes and modules are used right from the beginning, for example; the early programs do not use a subset of the language that’s later expanded by the introduction of more sophisticated features such as classes.


The English text of this work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

This license forbids publishing and selling copies of the book, but you are free to print copies for your own private or educational use. For example, it’s OK to print out a section as a handout for a class, or to include sections in documents that you write and make available under the same Creative Commons license.

If you wish to sell copies of the book or include partial sections of the text in your own works made available under a different license, please contact the author to request permission.

The software programs are released under the MIT license, and you are free to use or modify them in any way you like, including for commercial purposes or in other documentation projects.

The original source text and example code is available at, and is formatted using the Sphinx documentation tool (

Please send questions, suggestions, and comments to the e-mail address below.

A.M. Kuchling