Python is a general-purpose programming language.
A Python program requires an application called the Python interpreter to run it.
Python (i.e. the Python interpreter and other necessary files) is free and may be downloaded from www.python.org
Python runs under Windows, Unix/Linux, and Mac OSX.
Python has good documentation, including a nice tutorial, available with the download.
Python is named by its creator, Guido van Rossum, after the comedy group Monty Python, not after the snake.
Most software undergoes development/maintenance.
Development/maintenance happen for a number of reasons:
- Correction - fix errors
- Adaptation - modify to accommodate changes in the external environment
- Enhancement - add additional functionality
- Prevention - make changes to facilitate easier correction, adaptation, and enhancement
Version numbers are assigned to software as it is released to keep track of what features, etc. that release has.
Users don't always use the newest version immediately so for any application there will usually be a number of versions currently in use. Note: This will not be the case for web software since everyone will use the same website.
The current version of Python is 3.x, Python 3. (Check www.python.org to see the exact version).
Many users are still using version 2.7.x., Python 2.
There are some incompatibilites between Python 2.7.x and Python 3.x.
- Output is different
- Input is different
- Division of integers loses the fractional part in Python 2.7, it is not lost in Python 3.
Thus a program written for Python 2 will likely need modification to run under Python 3.
If a person knows a version of Python, then the person can make adjustments according to the actual version of Python that is used.
For this class, we will use Python 3.5.x
A program written by a programmer is called a source program.
An instruction written in a programming language is often called a statement.
A repetition statement is often called a loop.
Compilers and Interpreters
The computer hardware can only directly execute programs of a type called machine language.
There are two schemes for dealing with this called :
- Compiling - A program called a compiler is used to process the source program and produce a machine language version. The resulting machine language program may be run and is directly executed by the hardware.
This is a two step process, compile and run (execute).
- Interpreting - The source program is executed by another program called an interpreter. The interpreter reads the statements of the source program and, according the the statement, causes the specified action to happen.
This is a one step process, run.
Usually a programming language employs one or the other, not both, although there is no reason both could not be used for the same language.
Python uses an interpreter and is thus an interpreted language.
Actually an interpreter typically inputs the entire program and converts it to an internal "shorthand" notation before beginning execution and then executes the "shorthand" version.
This allows faster execution and syntax errors can be detected during the conversion process.
Running Python Programs
The Python interpreter is used to run Python programs.
The Python interpreter may also be used interactively.
Python has an Integrated DeveLopment Environment available, called IDLE, that runs the interpreter as described above.
Python Language Syntax
The Python programming language, like any programming language, defines the format allowable statements may have, the syntax.
Statements that do not follow the defined format will produce an error message.
Many programming languages indicate statement groups by putting them in curly braces or use a special work like EndLoop at the end.
In Python indentation is used to denote groups of statements.
Adjacent statements indented the same amount are part of the same group.
Typical indentation is 4 spaces but any amount is acceptable.
It is a syntax error if the indentation in a group of statements is not consistent.
Programming languages allow programmers to type in explanatory information that will be ignored when the program is run.
This added information is called a comment.
Comments provide descriptive information and are not program instructions.
The Python interpreter ignores comments when it is running a program.
In the Python programming the # character denotes a comment.
On a line that has a # everything from the # to the end of the line is a comment and is ignored when the program is run.