An Introduction to Programming Using Python
I wrote this book over the winter of 2011. We used it this Fall in our intro programming classes. I am making it available for free under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
Please send comments, corrections, and suggestions to
Description of the book
My goal here is for something that is partly a tutorial and partly a reference book. I like how tutorials get you up and running quickly, but they can often be a little wordy and disorganized. Reference books contain a lot of good information, but they are are often too terse, and they don't often give you a sense of what is important. My aim here is for something in the spirit of a tutorial but still useful as a reference. I summarize information in tables and give a lot of short example programs. I also like to jump right into things and fill in background information as I go, rather than covering the background material first.
This book started out as about 30 pages of notes for students in my introductory programming class at Mount St. Mary's University. Most of these students have no prior programming experience, and that has affected my approach. I leave out a lot of technical details and sometimes I oversimplify things. Some of these details are filled in later in the book, though other details are never filled in. But this book is not designed to cover everything, and I recommend reading other books and the Python documentation to fill in the gaps.
The style of programming in this book is geared towards the kinds of programming things I like to do---short programs, often of a mathematical nature, small utilities to make my life easier, and small computer games. In fact, the things I cover in the book are the things that I have found most useful or interesting in my programming experience, and this book serves partly to document those things for myself. This book is not designed as a thorough preparation for a career in software engineering. Interested readers should progress from this book to a book that has more on computer science and the design and organization of large programs.
The book is divided into three parts. The first part covers all the basics, including loops, conditionals, strings, lists, dictionaries, text files, functions, and object-oriented programming. The second part covers GUI programming with Tkinter. The third part consists of a variety of interesting intermediate topics that I have found useful over the years. The topics include a number of features of the language, regular expressions, the itertools and collections modules, functional programming, and a variety of useful modules.
Though this book was designed to be used in an introductory programming course, it is also useful for those with prior programming experience looking to learn Python. If you are one of those people, you should be able to breeze through the first several chapters. You should find Part II to be a concise, but not superficial, treatment on GUI programming. Part III contains information on the features of Python that allow you to accomplish big things with surprisingly little code.
Some of the exercises require data files. They will be posted here eventually...
Last updated February 4, 2012.