Dive Into Python
20 May 2004
Copyright (c) 2000, 2001, 2002, 2003, 2004 Mark Pilgrim (mailto:
Mark@diveintopython. org)
Else, you may not have the latest version.
Permission is granted to copy, distribute, and/or modify this document under
The terms of the GNU Free Documentation License, Version 1.1 or any later
Version published by the Free Software Foundation; with no Invariant Sections,
No Front-Cover Texts, and no Back-Cover Texts. A copy of the license is
Included in Appendix═G, GNU Free Documentation License.
The example programs in this book are free software; you can redistribute and/
Or modify them under the terms of the Python license as published by the Python
Software Foundation. A copy of the license is included in Appendix═H, Python
License.
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Table of Contents
══*═1. Installing Python
══+═1.1. Which Python is right for you?
══+═1.2. Python on Windows
══+═1.3. Python on Mac OS X
══+═1.4. Python on Mac OS 9
══+═1.5. Python on RedHat Linux
══+═1.6. Python on Debian GNU/Linux
══+═1.7. Python Installation from Source
══+═1.8. The Interactive Shell
══+═1.9. Summary
══*═2. Your First Python Program
══+═2.1. Diving in
══+═2.2. Declaring Functions
══o═2.2.1. How Python’s Datatypes Compare to Other Programming
Languages
══+═2.3. Documenting Functions
══+═2.4. Everything Is an Object
══o═2.4.1. The Import Search Path
══o═2.4.2.
What’s an Object?
══+═2.5. Indenting Code
══+═2.6. Testing Modules
══*═3. Native Datatypes
══+═3.1. Introducing Dictionaries
══o═3.1.1. Defining Dictionaries
══o═3.1.2. Modifying Dictionaries
══o═3.1.3. Deleting Items From Dictionaries
══+═3.2. Introducing Lists
══o═3.2.1. Defining Lists
══o═3.2.2. Adding Elements to Lists
══o═3.2.3. Searching Lists
══o═3.2.4. Deleting List Elements
══o═3.2.5. Using List Operators
══+═3.3. Introducing Tuples
══+═3.4. Declaring variables
══o═3.4.1. Referencing Variables
══o═3.4.2. Assigning Multiple Values at Once
══+═3.5. Formatting Strings
══+═3.6. Mapping Lists
══+═3.7. Joining Lists and Splitting Strings
══o═3.7.1. Historical Note on String Methods
══+═3.8. Summary
══*═4. The Power Of Introspection
══+═4.1. Diving In
══+═4.2. Using Optional and Named Arguments
══+═4.3. Using type, str, dir, and Other Built-In Functions
══o═4.3.1. The type Function
══o═4.3.2. The str Function
══o═4.3.3. Built-In Functions
══+═4.4. Getting Object References With getattr
══o═4.4.1. getattr with Modules
══o═4.4.2. getattr As a Dispatcher
══+═4.5. Filtering Lists
══+═4.6. The Peculiar Nature of and and or
══o═4.6.1. Using the and-or Trick
══+═4.7. Using lambda Functions
══o═4.7.1. Real-World lambda Functions
══+═4.8. Putting It All Together
══+═4.9. Summary
══*═5. Objects and Object-Orientation
══+═5.1. Diving In
══+═5.2.