Professional Documents
Culture Documents
1/28/11
9:29 AM
Page iii
Table of Contents
[CHAPTER]
1.1
1.1
1.2
1.2
1.3
1.4
1.4
1.5
1.5
[CHAPTER]
INTRODUCTION
2.1
2.1
2.2
39
1/28/11
9:29 AM
Page iv
2.3
2.3
2.4
2.4
2.5
2.5
2.6
2.6
[CHAPTER]
3.1
3.1
3.2
3.2
3.3
3.4
CONTROL STATEMENTS
75
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
1/28/11
9:29 AM
3.4
3.5
3.5
3.6
[CHAPTER]
4.1
4.1
4.2
4.2
4.3
4.3
4.4
4.4
4.5
Page v
3.4.3
3.4.4
3.4.5
3.4.6
3.4.7
121
1/28/11
9:29 AM
Page vi
[CHAPTER]
4.5
4.6
Exercises................................................................................................................148
Case Study: Text Analysis.....................................................................................148
4.6.1
Request .................................................................................................149
4.6.2
Analysis .................................................................................................149
4.6.3
Design...................................................................................................150
4.6.4
Implementation (Coding) ....................................................................151
4.6.5
Testing ..................................................................................................152
Summary ...............................................................................................................153
Review Questions .................................................................................................154
Projects..................................................................................................................156
5.1
5.1
5.2
5.2
5.3
5.4
5.4
159
Lists .......................................................................................................................160
5.1.1
List Literals and Basic Operators ........................................................160
5.1.2
Replacing an Element in a List ...........................................................163
5.1.3
List Methods for Inserting and Removing Elements .........................165
5.1.4
Searching a List....................................................................................167
5.1.5
Sorting a List........................................................................................168
5.1.6
Mutator Methods and the Value None ...............................................168
5.1.7
Aliasing and Side Effects......................................................................169
5.1.8
Equality: Object Identity and Structural Equivalence........................171
5.1.9
Example: Using a List to Find the Median of a Set of Numbers ......172
5.1.10 Tuples ...................................................................................................173
Exercises................................................................................................................174
Defining Simple Functions ..................................................................................175
5.2.1
The Syntax of Simple Function Definitions .......................................175
5.2.2
Parameters and Arguments..................................................................176
5.2.3
The return Statement.......................................................................177
5.2.4
Boolean Functions................................................................................177
5.2.5
Defining a main Function...................................................................178
Exercises................................................................................................................179
Case Study: Generating Sentences ......................................................................179
5.3.1
Request .................................................................................................179
5.3.2
Analysis .................................................................................................179
5.3.3
Design...................................................................................................180
5.3.4
Implementation (Coding) ....................................................................182
5.3.5
Testing ..................................................................................................183
Dictionaries...........................................................................................................183
5.4.1
Dictionary Literals ...............................................................................183
5.4.2
Adding Keys and Replacing Values .....................................................184
5.4.3
Accessing Values...................................................................................185
5.4.4
Removing Keys ....................................................................................186
5.4.5
Traversing a Dictionary .......................................................................186
5.4.6
Example: The Hexadecimal System Revisited....................................188
5.4.7
Example: Finding the Mode of a List of Values .................................189
Exercises................................................................................................................190
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
1/28/11
9:29 AM
[CHAPTER]
Page vii
5.5
6.1
6.1
6.2
6.2
6.3
6.3
6.4
6.5
6.5
6.6
201
1/28/11
9:29 AM
Page viii
[CHAPTER]
6.6
Exercises................................................................................................................239
Summary ...............................................................................................................240
Review Questions .................................................................................................242
Projects..................................................................................................................244
7.1
7.1
7.2
7.3
7.3
[CHAPTER]
8.1
247
293
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
1/28/11
9:29 AM
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
8.1
8.2
8.3
8.3
8.4
8.5
8.5
[CHAPTER]
9.1
9.1
9.2
Page ix
8.1.4
8.1.5
8.1.6
8.1.7
8.1.8
349
1/28/11
9:29 AM
Page x
9.2
9.3
9.4
9.4
[CHAPTER]
9.2.5
9.2.6
10
10.1
10.1
10.2
10.2
10.3
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
Cengage Learning. All rights reserved. No distribution allowed without express authorization.
1/28/11
9:29 AM
[ONLINE CHAPTER]
11
11.1
11.1
11.2
11.2
11.3
11.3
11.4
11.4
11.5
11.6
11.7
[APPENDIX]
A.1
A.2
[APPENDIX]
[APPENDIX]
[APPENDIX]
B
C
D
Page xi
PYTHON RESOURCES
433
437
439
441
GLOSSARY
443
INDEX
455