SPECIAL OFFERS
Keep up with new releases and promotions. Sign up to hear from us.
Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is the Rough Cut version of the printed book.
You Will Learn Python!
Zed Shaw has perfected the world's best system for learning Python. Follow it and you will succeed-just like the hundreds of thousands of beginners Zed has taught to date! You bring the discipline, commitment, and persistence; the author supplies everything else.
In Learn Python the Hard Way, Third Edition, you'll learn Python by working through 52 brilliantly crafted exercises. Read them. Type their code precisely. (No copying and pasting!) Fix your mistakes. Watch the programs run. As you do, you'll learn how software works; what good programs look like; how to read, write, and think about code; and how to find and fix your mistakes using tricks professional programmers use. Most importantly, you'll learn the following, which you need to start writing excellent Python software of your own:
It'll be hard at first. But soon, you'll just get it-and that will feel great!
This tutorial will reward you for every minute you put into it. Soon, you'll know one of the world's most powerful, popular programming languages. You'll be a Python programmer.
Watch Zed, too! The accompanying DVD contains 5+ hours of passionate, powerful teaching: a complete Python video course!
Preface 1
Acknowledgments 1
The Hard Way Is Easier 1
Do Not Copy-Paste 2
A Note on Practice and Persistence 3
A Warning for the Smarties 3
Exercise 0: The Setup 6
Mac OSX 6
Windows 7
Linux 9
Warnings for Beginners 10
Exercise 1: A Good First Program 12
What You Should See 14
Study Drills 15
Common Student Questions 16
Exercise 2: Comments and Pound Characters 18
What You Should See 18
Study Drills 18
Common Student Questions 19
Exercise 3: Numbers and Math 20
What You Should See 21
Study Drills 21
Common Student Questions 22
Exercise 4: Variables and Names 24
What You Should See 25
Study Drills 25
Common Student Questions 25
Exercise 5: More Variables and Printing 28
What You Should See 28
Study Drills 29
Common Student Questions 29
Exercise 6: Strings and Text 30
What You Should See 31
Study Drills 31
Common Student Questions 31
Exercise 7: More Printing. 32
What You Should See 32
Study Drills 32
Common Student Questions 33
Exercise 8: Printing, Printing 34
What You Should See 34
Study Drills 34
Common Student Questions 34
Exercise 9: Printing, Printing, Printing 36
What You Should See 36
Study Drills 36
Common Student Questions 37
Exercise 10: What Was That? 38
What You Should See 39
Escape Sequences 39
Study Drills 40
Common Student Questions 40
Exercise 11: Asking Questions 42
What You Should See 42
Study Drills 43
Common Student Questions 43
Exercise 12: Prompting People 44
What You Should See 44
Study Drills 44
Common Student Questions 45
Exercise 13: Parameters, Unpacking, Variables 46
Hold Up! Features Have Another Name 46
What You Should See 47
Study Drills 48
Common Student Questions 48
Exercise 14: Prompting and Passing 50
What You Should See 50
Study Drills 51
Common Student Questions 51
Exercise 15: Reading Files 54
What You Should See 55
Study Drills 55
Common Student Questions 56
Exercise 16: Reading and Writing Files 58
What You Should See 59
Study Drills 59
Common Student Questions 60
Exercise 17: More Files 62
What You Should See 63
Study Drills 63
Common Student Questions 63
Exercise 18: Names, Variables, Code, Functions 66
What You Should See 67
Study Drills 68
Common Student Questions 68
Exercise 19: Functions and Variables 70
What You Should See 71
Study Drills 71
Common Student Questions 71
Exercise 20: Functions and Files 74
Wh