blob: 53cf55b15ee69b3914be40088fa83b0ed5ecff3a [file] [log] [blame]
Guido van Rossuma7925f11994-01-26 10:20:16 +00001What is Python?
2---------------
3
4Python is an interpreted, interactive, object-oriented programming
5language. It incorporates modules, exceptions, dynamic typing, very
6high level dynamic data types, and classes. Python combines
7remarkable power with very clear syntax. It has interfaces to many
8system calls and libraries, as well as to various window systems, and
9is extensible in C or C++. It is also usable as an extension language
10for applications that need a programmable interface. Finally, Python
11is portable: it runs on many brands of UNIX, on the Mac, and on
12MS-DOS.
13
14As a short example of what Python looks like, here's a script to
15print prime numbers (not blazingly fast, but readable!). When this
16file is made executable, it is callable directly from the UNIX shell
17(if your system supports #! in scripts and the python interpreter is
18installed at the indicated place).
19
20#!/usr/local/bin/python
21
22# Print prime numbers in a given range
23
24def main():
25 import sys
26 min, max = 2, 0x7fffffff
27 if sys.argv[1:]:
28 min = int(eval(sys.argv[1]))
29 if sys.argv[2:]:
30 max = int(eval(sys.argv[2]))
31 primes(min, max)
32
33def primes(min, max):
34 if 2 >= min: print 2
35 primes = [2]
36 i = 3
37 while i <= max:
38 for p in primes:
39 if i%p == 0 or p*p > i: break
40 if i%p <> 0:
41 primes.append(i)
42 if i >= min: print i
43 i = i+2
44
45main()