Python (part 1)


Python, which you'll be learning the basics of, is a general-purpose programming
language.  You will be writing python programs using an editor, and then running
these programs on the computer.

First of all:  most languages are classified as being "high-level" or "low-level".
A low-level language can be thought of as being done in assembly language for
a particular architecture.  An assembly language instruction typically looks like
ADD R6,R4  meaning add the contents of registers 6 and 4 or LOAD  R6,VAL
meaning load the contents of the memory variable VAL into register 6.  Low-level
languages are not very portable, since, for example, the architecture and assembly
language for a PC is different from that of an Apple Mac.  Most assembly language
instructions translate into machine instructions (e.g. 5A064B00) on a one-to-one
basis.  High-level languages are much more portable, and most high-level language
instructions have to be translated into multiple machine instructions.  An assembler
translates assembly code into executable machine code.  A compiler translates
high-level instructions into machine code.  But there are also interpreters, which
step through high-level programs line by line, carrying out each line one at a time.
The language Basic is traditionally interpreted rather than compiled, but there are
compilers for Basic:  compiled Basic runs a whole lot faster than interpreted Basic.
Python is a kind of hybrid compiler-interpreter:  Python compiles source code into
what is called Python bytecode (which is NOT the same as machine code) and this
bytecode is then interpreted.  Python is usually referred to as an interpreted
language, but to confuse matters,  there are tools which can also compile Python
into machine code.   In the rest of these notes about Python, I'll often be referring
to the "Python compiler"--remember that it's actually a compiler/interpreter.

Before compiling your Python program into bytecode, Python examines your
code for errors--nobody is able to write perfect error-free code at all times.
Only if Python cannot find any errors will it produce a runnable (which means
interpretable in this case) bytecode module.  Python points out errors in your
source code:  you fix the error and try again...and again.  It may take a while to
get things right!  We need to point out that even if Python finds no errors in your
code, that doesn't mean the code will actually run correctly.  Think of the English
language.  Syntax means the sentence structure.  Let's consider only simple sentences: 
   article --  adjective -- adjective -- noun --  transitive verb --  article --
    adjective -- noun
For example:  The big green frog ate a small fly.  This sentence is syntactically
correct for our prescribed sentence pattern.  The sentence is also semantically
correct--it makes sense.    Consider:  The large small frog bought a purple July.
This sentence is also syntactically correct--but it makes no sense semantically!
A compiler checks the syntax of your program, but it cannot read your mind to
figure out what you intend the program to do.

USING AN EDITOR TO CREATE A PROGRAM.  Notepad, which you have
used, is an editor.  It creates simple text files--what you type in is what you get.
You used Notepad to create html files.  There are also special-purpose html
editors (e.g. DreamWeaver) designed for creating web pages.  Could you have
used Word to create your html pages?  Well--and you won't like this-- the
answer is yes AND no.  Word embeds hidden instructions that specify things
like font size, italics, etc.  These are not valid html instructions, and so an html
file cannot work properly.  (Notepad does strictly text).  Word does, however,
have an option that lets you save a document as an html file--Word translates
its own embedded instructions into html instructions.   To see what Word does,
you can create a short Word document.  Then open this document with Notepad.
It will be rather confusing--it would also be confusing for a web browser
expecting normal html or for a compiler expecting normal source code for, say,
a Python program.  Even more confusing would be a graphics editor--these are
designed to help edit jpg, gif, etc graphics files--so remember--use a proper
editor for what you need--whether it's graphics, html, Python, etc.

You can create Python programs using Notepad--but do NOT try to use Word
to do this--Python compilers will not be happy with the embedded Word
instructions.  But even better than Notepad for your purposes will be the
special-purpose Python editor that you will use.  There are lots of such
special-purpose language editors out there.  I personally use the Bloodshed
C/C++ editor/compiler to write C programs on my PCs at home and at work,
as well as the same Python editor/compiler that you'll be using.  Such a special-
purpose editor can make your life much easier when you write programs--as
you'll see, they can use different colors to highlight different features of the
language and there are many other helpful features as well.  We'll lead you
through a number of labs that teach the basics of the Python programming
language.  Writing simple programs isn't too bad.  You are not expected to
produce complex code such as a senior in Computer Science or Computer
Engineering might write.  But what we do want to do is to acquaint you with
the essential concepts of what goes into a computer program.  If you want a
swimming analogy, we're going to teach you to dog paddle--we are not going
to teach you how to compete in Olympic or even UT intermural swimming
matches!  So don't panic!