Intro to Python

Since I'm starting to learn Python programming for my Colonial Marines RPG, I thought I might as well make a tutorial for others while I'm at it. Since I'm a beginner Python programmer, I figured I'd be in a good place to show others how to use the language, my thoughts on it, and what mistakes I've made and learned from.

I have programmed before (C, C++, Java) for college but nothing really serious. I didn't really like the low-level work involved with C/C++ and Java, as my first programming class in school, didn't make any sense. Hopefully Python won't be as bad.

Python is regarded as being a great hobbyist language yet extremely powerful. It has bindings for C/C++ and Java so it can be used to tie large projects together or for rapid prototyping. It has a built-in GUI binding via Tkinter but other GUI builders are available. It can be used in a real-time interpreter for code testing then built into a normal "executable".

Python is based on the C programming language and is written in C, so much of the format Python uses will be familiar to C and C++ programmers. However, it makes life a little easier because it's not made to be a low-level language (it's difficult to interact heavily with hardware or perform memory allocation) and it has built-in "garbage collection" (it tracks references to objects and automatically removes objects from memory when they are no longer referenced), which allows the programmer to worry more about how the program will work rather than dealing with the computer.

Even though there are several great tutorials at the Python web site in addition to many books, my emphasis will be on the practical features of the language, i.e. I won't go into the history of the language or the esoteric ways it can be used. I will assume you either have some experience programming or can at least follow the code flow. You can download Python from the web site or it may already be installed on your system if you're using a Mac, Linux, or *BSD. I'll also assume you can figure out how to get the interactive interpreter running; if you need help, read the help pages on the web site.

One final note:  many of the examples used in this tutorial are from Learning Python, 2nd edition from O'Reilly Publishing.  It's a fantastic book for those starting out in Python or even for use as a bookshelf reference.