Table of Contents
Dive Into Python...............................................................................................................................................................1
Chapter 1. Installing Python...........................................................................................................................................2
1.1. Which Python is right for you?......................................................................................................................2
1.2. Python on Windows.......................................................................................................................................2
1.3. Python on Mac OS X.....................................................................................................................................3
1.4. Python on Mac OS 9......................................................................................................................................5
1.5. Python on RedHat Linux...............................................................................................................................5
1.6. Python on Debian GNU/Linux......................................................................................................................6
1.7. Python Installation from Source....................................................................................................................6
1.8. The Interactive Shell......................................................................................................................................7
1.9. Summary........................................................................................................................................................8
Chapter 2. Your First Python Program.........................................................................................................................9
2.1. Diving in........................................................................................................................................................9
2.2. Declaring Functions.......................................................................................................................................9
2.3. Documenting Functions...............................................................................................................................10
2.4. Everything Is an Object...............................................................................................................................11
2.5. Indenting Code.............................................................................................................................................13
2.6. Testing Modules...........................................................................................................................................14
Chapter 3. Native Datatypes.........................................................................................................................................15
3.1. Introducing Dictionaries..............................................................................................................................15
3.2. Introducing Lists..........................................................................................................................................17
3.3. Introducing Tuples.......................................................................................................................................22
3.4. Declaring variables......................................................................................................................................23
3.5. Formatting Strings.......................................................................................................................................25
3.6. Mapping Lists..............................................................................................................................................26
3.7. Joining Lists and Splitting Strings...............................................................................................................28
3.8. Summary......................................................................................................................................................29
Chapter 4. The Power Of Introspection.......................................................................................................................31
4.1. Diving In......................................................................................................................................................31
4.2. Using Optional and Named Arguments.......................................................................................................32
4.3. Using type, str, dir, and Other Built−In Functions......................................................................................33
4.4. Getting Object References With getattr.......................................................................................................36
4.5. Filtering Lists...............................................................................................................................................38
4.6. The Peculiar Nature of and and or...............................................................................................................39
4.7. Using lambda Functions..............................................................................................................................41
4.8. Putting It All Together.................................................................................................................................43
4.9. Summary......................................................................................................................................................45
Chapter 5. Objects and Object−Orientation...............................................................................................................47
5.1. Diving In......................................................................................................................................................47
5.2. Importing Modules Using from module import...........................................................................................49
5.3. Defining Classes..........................................................................................................................................50
5.4. Instantiating Classes.....................................................................................................................................53
5.5. Exploring UserDict: A Wrapper Class........................................................................................................54
5.6. Special Class Methods.................................................................................................................................56
5.7. Advanced Special Class Methods................................................................................................................59
Dive Into Python i
评论0