Paul's Python Intro 01

Paul Dickson plug-devel@lists.PLUG.phoenix.az.us
Thu Sep 9 12:27:02 2004


It's been a long time since there's been a universal programming language
the likes of BASIC.  At one point, just about every personal computer came
with it, usually built directly into the ROM in lieu of a operating
system.  But now I think I've found another language that's available for
every machine, be it Windows, Mac, Linux, and mainframes; and no, it's not
Java.

I'm talking about a language called Python (named in honor of Monty
Python's Flying Circus).  It is both a compiled language like Java, but it
also contains an interpreter that can be used very similarly to the way
BASIC was on those old PCs.  The interpreter can be used simply as an
advanced calculator, or a test bed for developing programs.

Unless you are running a distribution of Linux, you will have to download
this programming language.  You'll find it on the web at:

	http://www.python.org/download/

I'll leave the installation up to you, but please post any problems you
might have to this mailing list.  Either I, or someone else can then help
you.

On the above site, there are links to documentation and tutorials, so this
series of articles won't be an in-depth look at the language, but more a
quick look with examples.

You can get to the interpreter in at least two ways: open a Command Prompt
session and typing python, or launching IDLE.  From my terminal window on
Linux, when I type "python", I get:

    Python 2.3.3 (#1, May  7 2004, 10:31:40)
    [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

You should get something similar.  To exit, press-and-hold the control key
and press Z.  On Windows, this signals an End-of-File, so the program
stops reading input and exits.  On Linux, the same function is Ctrl-D.

The >>> is a prompt.  The cursor is waiting there for input.

    >>> 3+4*5
    23
    >>> a=3; b=6
    >>> a+b
    9
    >>> c=a*b
    >>> print c
    18
    >>> a="Testing"
    >>> a.lower()
    'testing'
    >>> a[:4]
    'Test'
    >>> print a[:4]
    Test
    >>>

This briefly shows some math, assigning variables, text strings, and
slices of strings.

Actually try the examples I give.  This will give you a better feeling for
what's going on with the interpreter than just reading my examples.

In my next message I'll briefly cover strings

If you want a lot more info about this language, I recommend the book
"Learning Python" by Mark Lutz and David Ascher, especially if you already
know how to program in other languages.  The second edition is only about
9 months old and cover Python 2.3, so it's very up-to-date.

	-Paul