Python is, in short, a scripting language. It is similar in function to Perl, but to my knowledge is not nearly as popular. To fix that is part of the goal of this tutorial. It is a very high-level language that can perform complex tasks, but is surprisingly easy to learn. Many different add=ons (modules) are available to control everything from MP3s to windowing toolkits (Unix). I find Python to be a just plain fun language to program in, as it is very intuitive and suited to a variety of uses.
Python can be run on almost any platform, from ‘nix to Windows. To get Python, first go to Python.org, and then download away!
This tutorial is geared towards people who have little experience with programming but know at least something. I make numerous references to languages like C and Perl, which are good to know, but you won’t lose much if you just skip over them.
What’s with the funky name, you ask? Some sort of carnivorous reptile? No, dear reader. Python’s creators were (are) big Monty Python fans. The name comes from the BBC show “Monty Python’s Flying Circus,” and in the official docs, it says “Making references to Monty Python skits in documentation is not only allowed, it is encouraged.” That said, I’m afraid I haven’t seen all too many Monty Python movies so we’ll go a little light on the references.
Why Python is Better than Perl
I admit it: maybe Python isn’t better than Perl. It’s different, to say the least. For many things it is better. And it’s got definite advantages, and that’s what I thought I’d just review, or look at, or list, or whatever. Here goes.
- Intuitiveness. Instead of all that nasty, obfuscated code, Python has syntax and blocking that resembles, somewhat, normal (English) speech and indenting.
- High-levelness. List slicing, tuple packing, etc. allow for high-level manipulation of data without all that mucking about with pointers…wait…that’s C…and efficient though it may be, it sometimes even confuses the überhacker in me. But it’s still easier in Python than Perl.
- More integrated object-oriented (OO) support. OO in Perl involves working with hashes as classes and weird stuff like that. Bottom line, Python was designed from the start to be OO…even though I didn’t talk about classes too much. Sorry.
- Better C integration. Well, this is opinionated here, but I think embedding Python in C is easier than Perl…what can I say?
- Interactive mode. No need to put scripts in separate files. You know what I’m saying.
- Wider variety of data structures. Perl has arrays, hashes, and scalars. Python has scalars (int, float, long), lists, dictionaries (which I didn’t talk about; they’re like hashes or associative arrays), tuples. And it’s extensible and evolving, according to the docs.
- range function. People complain about the lack of a generic for loop, like Perl has. range really makes the for loop…without having a whole different type of loop. Less overhead. And you can use range for other things, too.