Python Tutorial

---
node1.html node1.html
---
# Python Tutorial
Guido van Rossum
Dept. AA, CWI, P.O. Box 94079
1090 GB Amsterdam, The Netherlands
E-mail: guido@cwi.nl
13 October 1995
Release 1.3
Copyright © 1991-1995 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
### Abstract:
Python is a simple, yet powerful programming language that bridges the
gap between C and shell programming, and is thus ideally suited for
``throw-away programming''
and rapid prototyping. Its syntax is put
together from constructs borrowed from a variety of other languages;
most prominent are influences from ABC, C, Modula-3 and Icon.
The Python interpreter is easily extended with new functions and data
types implemented in C. Python is also suitable as an extension
language for highly customizable C applications such as editors or
window managers.
Python is available for various operating systems, amongst which
several flavors of Unix, Amoeba, the Apple Macintosh O.S.,
and MS-DOS.
This tutorial introduces the reader informally to the basic concepts
and features of the Python language and system. It helps to have a
Python interpreter handy for hands-on experience, but as the examples
are self-contained, the tutorial can be read off-line as well.
For a description of standard objects and modules, see the Python
Library Reference document. The Python Reference Manual gives
a more formal definition of the language.
---
- Contents (node1.html#SECTION00100000000000000000)
Whetting Your Appetite (node2.html#SECTION00200000000000000000)
- Where From Here (node3.html#SECTION00210000000000000000)
Using the Python Interpreter (node4.html#SECTION00300000000000000000)
- Invoking the Interpreter (node5.html#SECTION00310000000000000000)
- Argument Passing (node6.html#SECTION00311000000000000000)
Interactive Mode (node7.html#SECTION00312000000000000000)
The Interpreter and its Environment (node8.html#SECTION00320000000000000000)
- Error Handling (node9.html#SECTION00321000000000000000)
The Module Search Path (node10.html#SECTION00322000000000000000)
``Compiled'' Python files (node11.html#SECTION00323000000000000000)
Executable Python scripts (node12.html#SECTION00324000000000000000)
The Interactive Startup File (node13.html#SECTION00325000000000000000)
Interactive Input Editing and History Substitution (node14.html#SECTION00330000000000000000)
- Line Editing (node15.html#SECTION00331000000000000000)
History Substitution (node16.html#SECTION00332000000000000000)
Key Bindings (node17.html#SECTION00333000000000000000)
Commentary (node18.html#SECTION00334000000000000000)
An Informal Introduction to Python (node19.html#SECTION00400000000000000000)
- Using Python as a Calculator (node20.html#SECTION00410000000000000000)
- Numbers (node21.html#SECTION00411000000000000000)
Strings (node22.html#SECTION00412000000000000000)
Lists (node23.html#SECTION00413000000000000000)
First Steps Towards Programming (node24.html#SECTION00420000000000000000)
More Control Flow Tools (node25.html#SECTION00500000000000000000)
- If Statements (node26.html#SECTION00510000000000000000)
For Statements (node27.html#SECTION00520000000000000000)
The range() Function (node28.html#SECTION00530000000000000000)
Break and Continue Statements, and Else Clauses on Loops (node29.html#SECTION00540000000000000000)
Pass Statements (node30.html#SECTION00550000000000000000)
Defining Functions (node31.html#SECTION00560000000000000000)
Odds and Ends (node32.html#SECTION00600000000000000000)
- More on Lists (node33.html#SECTION00610000000000000000)
The del statement (node34.html#SECTION00620000000000000000)
Tuples and Sequences (node35.html#SECTION00630000000000000000)
Dictionaries (node36.html#SECTION00640000000000000000)
More on Conditions (node37.html#SECTION00650000000000000000)
Comparing Sequences and Other Types (node38.html#SECTION00660000000000000000)
Modules (node39.html#SECTION00700000000000000000)
- More on Modules (node40.html#SECTION00710000000000000000)
Standard Modules (node41.html#SECTION00720000000000000000)
The dir() function (node42.html#SECTION00730000000000000000)
Output Formatting (node43.html#SECTION00800000000000000000)
Errors and Exceptions (node44.html#SECTION00900000000000000000)
- Syntax Errors (node45.html#SECTION00910000000000000000)
Exceptions (node46.html#SECTION00920000000000000000)
Handling Exceptions (node47.html#SECTION00930000000000000000)
Raising Exceptions (node48.html#SECTION00940000000000000000)
User-defined Exceptions (node49.html#SECTION00950000000000000000)
Defining Clean-up Actions (node50.html#SECTION00960000000000000000)
Classes (node51.html#SECTION001000000000000000000)
- A word about terminology (node52.html#SECTION001010000000000000000)
Python scopes and name spaces (node53.html#SECTION001020000000000000000)
A first look at classes (node54.html#SECTION001030000000000000000)
- Class definition syntax (node55.html#SECTION001031000000000000000)
Class objects (node56.html#SECTION001032000000000000000)
Instance objects (node57.html#SECTION001033000000000000000)
Method objects (node58.html#SECTION001034000000000000000)
Random remarks (node59.html#SECTION001040000000000000000)
Inheritance (node60.html#SECTION001050000000000000000)
- Multiple inheritance (node61.html#SECTION001051000000000000000)
Odds and ends (node62.html#SECTION001060000000000000000)
Recent Additions (node63.html#SECTION001100000000000000000)
- The Last Printed Expression (node64.html#SECTION001110000000000000000)
String Literals (node65.html#SECTION001120000000000000000)
- Double Quotes (node66.html#SECTION001121000000000000000)
Continuation Of String Literals (node67.html#SECTION001122000000000000000)
Triple-quoted strings (node68.html#SECTION001123000000000000000)
String Literal Juxtaposition (node69.html#SECTION001124000000000000000)
The Formatting Operator (node70.html#SECTION001130000000000000000)
- Basic Usage (node71.html#SECTION001131000000000000000)
Referencing Variables By Name (node72.html#SECTION001132000000000000000)
Optional Function Arguments (node73.html#SECTION001140000000000000000)
- Default Argument Values (node74.html#SECTION001141000000000000000)
Arbitrary Argument Lists (node75.html#SECTION001142000000000000000)
Lambda And Functional Programming Tools (node76.html#SECTION001150000000000000000)
- Lambda Forms (node77.html#SECTION001151000000000000000)
Map, Reduce and Filter (node78.html#SECTION001152000000000000000)
- Map. (node79.html#SECTION001152100000000000000)
Filter. (node80.html#SECTION001152200000000000000)
Reduce. (node81.html#SECTION001152300000000000000)
Continuation Lines Without Backslashes (node82.html#SECTION001160000000000000000)
Regular Expressions (node83.html#SECTION001170000000000000000)
Generalized Dictionaries (node84.html#SECTION001180000000000000000)
Miscellaneous New Built-in Functions (node85.html#SECTION001190000000000000000)
Else Clause For Try Statement (node86.html#SECTION0011100000000000000000)
New Class Features in Release 1.1 (node87.html#SECTION0011110000000000000000)
- New Operator Overloading (node88.html#SECTION0011111000000000000000)
Trapping Attribute Access (node89.html#SECTION0011112000000000000000)
Calling a Class Instance (node90.html#SECTION0011113000000000000000)
New in Release 1.2 (node91.html#SECTION001200000000000000000)
- New Class Features (node92.html#SECTION001210000000000000000)
Unix Signal Handling (node93.html#SECTION001220000000000000000)
Exceptions Can Be Classes (node94.html#SECTION001230000000000000000)
Object Persistency and Object Copying (node95.html#SECTION001240000000000000000)
- Persistent Objects (node96.html#SECTION001241000000000000000)
Copying Objects (node97.html#SECTION001242000000000000000)
Documentation Strings (node98.html#SECTION001250000000000000000)
Customizing Import and Built-Ins (node99.html#SECTION001260000000000000000)
Python and the World-Wide Web (node100.html#SECTION001270000000000000000)
Miscellaneous (node101.html#SECTION001280000000000000000)
New in Release 1.3 (node102.html#SECTION001300000000000000000)
- Keyword Arguments (node103.html#SECTION001310000000000000000)
Changes to the WWW and Internet tools (node104.html#SECTION001320000000000000000)
Other Language Changes (node105.html#SECTION001330000000000000000)
Changes to Built-in Operations (node106.html#SECTION001340000000000000000)
Library Changes (node107.html#SECTION001350000000000000000)
Other Changes (node108.html#SECTION001360000000000000000)
About this document ... (node109.html#SECTION001400000000000000000)
---
node1.html node1.html
---
---
guido@cwi.nl