作者:empty 页数:244 出版社:empty |
Think PythonPrefaceThe strange history of this bookIn January 1999I was preparing to teach an introductory programming class in Java.I hadtaught it three times and I was getting frustrated.The failure rate in the class was too highand, even for students who succeeded, the overall level of achievement was too low.One of the problems I saw was the books.They were too big, with too much unnecessarydetail about Java, and not enough high-level guidance about howto program.And they allsuffered from the trapdoor effect:they would start out easy, proceed gradually, and thensomewhere around Chapter 5 the bottom would fallout.The students would get too muchnew material, too fast, and I would spend the rest of the semester picking up the pieces,Two weeks before the first day of classes, I decided to write my own book.My goals were:·Keep it short.It is better for students to read 10 pages than not read 50 pages.·Be careful with vocabulary.I tried to minimize jargon and define each term at frstuse.
Build gradually To avoid trap doors, I took the most difficult topics and split them·Focus on programming, not the programming language.I included the minimumI needed a title, soon a whim I chose Howto Think Like a Computer Scientist.My first version was rough, but it worked.Students did the reading, and they understoodenough that I could spend class time on the hard topics, the interesting topics and(mostimportant) letting the students practice.I released the book under the GNU Free Documentation License, which allows users tocopy, modify, and distribute the book.What happened next is the cool part.Jeff Elk ner, a high schoolteacher in Virginia, adoptedmy book and translated it into Python, He sent me a copy of his translation, and I had theunusual experience of learning Python by reading my own book.As GreenTea Press, Ipublished the first Python version in 2001.In2003I started teaching atOl in College and I got to teach Python for the first time.Thecontrast with Java was striking.Students struggled less, learned more, worked on moreinteresting projects, and generally had alot more fun.into a series of small steps.useful subset of Java and left out the rest.
Frmal and natural languages
Debugging
Glssary
Exercises.
2 Variables, expressins and statements
2.1Assignment statements.
2.2Variable names
2.3Expressins and statements
2.4Script mde.
2.5rder f peratins, .7.
2.6String peratins
2.7Cmments
2.8Debugging
2.9Glssary
2.10 Exercises.
Functin calls,
Math functins,
Cmpsitin.
Adding new functins
Definitins and uses
Flw f executin.
Parameters and arguments.
Variables and parameters are lcal.
Stack diagrams.
3.10 Fruitful functins and vid functins.
3.11Why functins?
3.12
Debugging
3.13 Glssary.
3.14Exercises
4 Case study:interface design
4.1The turtle mdule.
4.2Simple repetitin
4.3Exercises, .
4.4Encap sula in
4.5Generalizatin.
4.6Interface design
4.7Refactring-.
4.8A develpment plan
4.9dcstring.
4.10 Debugging.
4.11Glssary
4.12 Exercises.
5 Cnditinals and recursin
5.10Infnite recursin
5.14 Exercises.
6 Fruitful functins
Reassignment
Updating variables
The sL:le statement
310a.
Square rts
Algrithms
Debugging-
Glssary:
Exercises
A string is a sequence.
Traversal with at r lp.
String slices
Strings are immutable
Searching.
Lping and cunting
String methds.
Their peratr
String cmparisn
Debugging.
Flr divisin and mdulus,
Blean expressins.
Lgical peratrs
Cnditinal executin
Alternative executin.
Chained cnditinals
Nested cnditinals.
Recursin.
Stack diagrams fr recursive functins,
Keybard input.
Debugging.
Glssary
Re tum values.
Incremental develpment
Cmpsitin:
Blean functins.
Mre recursin.
Leap f faith
ne mre example
Checking types
Debugging-
Glssary
Exercises
7 Iteratin
8 Strings
8.12 Glssary
8.13 Exercises
9 Case study:wrdplay
9.1Reading wrdlists
9.2Exercises.
9.3Search.
9.4Lping with indices.
9.5Debugging.
9.6Glssary·
9.7Exercises
A list is a sequence.
Lists are mutable
Traversing alst.
List peratins
List slices,
List methds.
10.7Map, fit er and reduce.
10.8Deleting elements
10.9Lists and strings, .
10.10 bjects and values
10.11 Aliasing.
10.12 List arguments.
10.13 D