Ten Small Python Programs

May 29th, 2007 § 0 comments

A comp.lang.python thread caught my eye (after I was done goug­ing them out after read­ing the PEP8 dis­cus­sion — we lovesOur­Boun­cy­Name) enti­tled “Ten Small Python Pro­grams”. To quote Steve Howell:

I’ve always thought that the best way to intro­duce new
pro­gram­mers to Python is to show them small code
examples.When you go to the tuto­r­ial, though, you have to wade
through quite a bit of Eng­lish before see­ing any
Python examples.

Below is my attempt at gen­er­at­ing ten fairly sim­ple,
rep­re­sen­ta­tive Python pro­grams that expose new users
to most basic con­cepts, as well as the over­all syntax.

It was an inter­est­ing exer­cise. I con­strained myself
to ten lines or less, and it was pretty easy to
incor­po­rate loops, con­di­tion­als, print, open(), lists,
tuples, dic­tio­nar­ies, and imported modules.

It was harder to show classes, and my Shop­ping­Cart
class is noth­ing more than an encap­su­la­tion of a list,
which has dubi­ous value (although it’s the start of
some­thing more useful).

This is a fan­tas­tic idea. This fol­lows the same type of teach­ing style a fel­low at work and I used to explain Python con­cepts to Java guys new to Python. Steve started a python wiki page here.

What's this?

You are currently reading Ten Small Python Programs at jessenoller.com.

meta