Saturday, July 28, 2007

Hello World in Python

Python is a very high-level interpreted scripting language. I have a personal interest in learning it, as it seems to be a great rapid prototyping language. You can quickly and easily write your logic in Python, just to see if it works. If it does rewrite the whole thing (or just resource-intensive chunks) in a compiled language like C++. When I say "quickly and easily," I'm serious. Here's an entire Python Hello World program:

print "Hello World"

As that doesn't tell you much, I'll add some variables and an infinite while loop:


var a,b = "hello", "world"
while true:
    print a + b


As you can see, Python has essentially no punctuation requirements (braces, semicolons and the like). It is entirely newline- and whitespace-delimited. Blocks are indicated by indentation. The command is done when you go to the next line. No more debugging a missing curly brace (yeah, yeah, IDE's catch that. Still, it's slick).

The other thing I can see Python being good for (and it's used for this in several schools I know of) is an introduction to programming. It gives you the basics of statements and control structures and loops and even OOP, and it even forces good programming style with the indentations, but it doesn't saddle you with learning all the intricacies of C++ or Java, for example.

1 comment:

Anonymous said...

OH DEAR LORD.

WRITE ABOUT ME OR SOMETHING.