Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 1 | What is Python? |
| 2 | --------------- |
| 3 | |
| 4 | Python is an interpreted, interactive, object-oriented programming |
| 5 | language. It incorporates modules, exceptions, dynamic typing, very |
| 6 | high level dynamic data types, and classes. Python combines |
| 7 | remarkable power with very clear syntax. It has interfaces to many |
| 8 | system calls and libraries, as well as to various window systems, and |
| 9 | is extensible in C or C++. It is also usable as an extension language |
| 10 | for applications that need a programmable interface. Finally, Python |
| 11 | is portable: it runs on many brands of UNIX, on the Mac, and on |
| 12 | MS-DOS. |
| 13 | |
| 14 | As a short example of what Python looks like, here's a script to |
| 15 | print prime numbers (not blazingly fast, but readable!). When this |
| 16 | file is made executable, it is callable directly from the UNIX shell |
| 17 | (if your system supports #! in scripts and the python interpreter is |
| 18 | installed at the indicated place). |
| 19 | |
| 20 | #!/usr/local/bin/python |
| 21 | |
| 22 | # Print prime numbers in a given range |
| 23 | |
| 24 | def 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 | |
| 33 | def 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 | |
| 45 | main() |