Introduction
Python has become one of the most popular programming languages among developers
and programmers. They praise it for its clean syntax and code readability.
Python is a general-purpose high-level programming language.
Python is both object oriented and imperative and it can be even used in a functional
style as well. Python programs are portable, i.e. the can pe ported to other operating
systems like Windows, Linux, Unix and Mac OS X, and the can be run on the Java and .NET
virtual machines.
Guido van Rossum, the author of Python, began work on Python at the National Research
Institute for Mathematics and Computer Science in the Netherlands (Centrum voor
Wiskunde en Informatica, CWI).
When asked, what features of Python he is most pleased with, Guido van Rossum said in
an interview with Linux Journal: "The feel of the whole system suits my style of
programming well, for obvious reasons. The ability to run the interpreter interactively
and the ability to write code from the bottom up and test it piecemeal combine to let
me write code quickly. Other people find that it makes them more productive, too." (LJ, no 55)
Python is very fast. The source code is compiled into bytecode, so that executing the same file
will be faster if the script will be executed again. The bytecode is an "intermediate language"
which is said to run on a virtual machine that executes the machine code corresponding to
each bytecode.
Comparing Python with Java, Perl and other Programming Languages
Prof. Lutz Prechelt from the University of Karlsruhe compared Python with other programming languages. He summarises his results: "80 implementations of the same set of requirements are compared for several properties, such as run time, memory consumption, source text length, comment density, program structure, reliability, and the amount of effort required for writing them. The results indicate that, for the given programming problem, which regards string manipulation and search in a dictionary, 'scripting languages' (Perl, Python, Rexx, Tcl) are more productive than 'conventional languages' (C, C++, Java). In terms of run time and memory consumption, they often turn out better than Java and not much worse than C or C++. In general, the differences between languages tend to be smaller than the typical differences due to different programmers within the same language. (see Lutz Prechelt, An empirical comparison of C, C++, Java, Perl, Python, Rexx, and Tcl, IEEE Computer, Vol. 30, (10), p. 23-29, Oct 2000.)
Other Advantages of Python
It's surprisingly easy to embed Python, or better the Python interpreter into C programs. By doing this you can add features from Python that could take months to code them in C. Vice versa, it's possible to extend the Python interpreter by adding a module written in C. One reason to do this is if a C library exists that does something which Python doesn't. Another good reason is if you need something to run faster than you can manage in Python.
The Python Standard Library contains an enorous number of useful modules and is part of every standard Python installation. After having learnt the essentials of Python, it is necessary to become familiar with the Python Standard Library because many problems can be solved quickly and easily if you are acquainted with the possibilities that these libraries offer.
Online Course
Further Topics
Examples:
A simple example illustrating a while loop. It calculates the sum of the first 100 numbers:
n = 100
sum = 0
i = 1
while i <= n:
sum = sum + i
i = i + 1
print "Sum of 1 to %d: %d" % (n,sum)
The faculty funtion in Python:
def fac(x):
if x > 1:
return x * fac(x - 1)
else:
return 1

