Advance Praise for Head First Programming“Head First Programming does a great job teaching programming using an iterative process.. I’d also recommend this book to anyone not necessarily
Trang 3Advance Praise for Head First Programming
“Head First Programming does a great job teaching programming using an iterative process Add a little,
explain a little, make the program a little better This is how programming works in the real world
and Head First Programming makes use of that in a teaching forum I recommend this book to anyone
who wants to start dabbling in programming but doesn’t know where to start I’d also recommend this
book to anyone not necessarily new to programming, but curious about Python It’s a great intro to
programming in general and programming Python specifically.”
— Jeremy Jones, Coauthor of Python for Unix and Linux System Administration
“David Griffiths and Paul Barry have crafted the latest gem in the Head First series Do you use a
computer, but are tired of always using someone else’s software? Is there something you wish your
computer would do but wasn’t programmed for? In Head First Programming, you’ll learn how to write
code and make your computer do things your way.”
— Bill Mietelski, Software Engineer
“Head First Programming provides a unique approach to a complex subject The early chapters make
excellent use of metaphors to introduce basic programming concepts used as a foundation for the rest
of the book This book has everything, from web development to graphical user interfaces and game
programming.”
— Doug Hellmann, Senior Software Engineer, Racemi
“A good introduction to programming using one of the best languages around, Head First Programming
uses a unique combination of visuals, puzzles, and exercises to teach programming in a way that is
approachable and fun.”
— Ted Leung, Principal Software Engineer, Sun Microsystems
Trang 4Praise for other Head First books
“Kathy and Bert’s Head First Java transforms the printed page into the closest thing to a GUI you’ve ever
seen In a wry, hip manner, the authors make learning Java an engaging ‘what’re they gonna do next?’ experience.”
— Warren Keuffel, Software Development Magazine
“Beyond the engaging style that drags you forward from know-nothing into exalted Java warrior status, Head
First Java covers a huge amount of practical matters that other texts leave as the dreaded ‘exercise for the
reader ’ It’s clever, wry, hip and practical—there aren’t a lot of textbooks that can make that claim and live
up to it while also teaching you about object serialization and network launch protocols.”
— Dr Dan Russell, Director of User Sciences and Experience Research
IBM Almaden Research Center (and teaches Artificial Intelligence at
Stanford University)
“It’s fast, irreverent, fun, and engaging Be careful—you might actually learn something!”
— Ken Arnold, former Senior Engineer at Sun Microsystems
Coauthor (with James Gosling, creator of Java), The Java Programming
Language
“I feel like a thousand pounds of books have just been lifted off of my head.”
— Ward Cunningham, inventor of the Wiki and founder of the Hillside Group
“Just the right tone for the geeked-out, casual-cool guru coder in all of us The right reference for practi-cal development strategies—gets my brain going without having to slog through a bunch of tired, stale professor -speak.”
— Travis Kalanick, Founder of Scour and Red Swoosh
Member of the MIT TR100
“There are books you buy, books you keep, books you keep on your desk, and thanks to O’Reilly and the Head First crew, there is the penultimate category, Head First books They’re the ones that are dog-eared, mangled, and carried everywhere Head First SQL is at the top of my stack Heck, even the PDF I have for review is tattered and torn.”
— Bill Sawyer, ATG Curriculum Manager, Oracle
“This book’s admirable clarity, humor and substantial doses of clever make it the sort of book that helps even non-programmers think well about problem-solving.”
— Cory Doctorow, co-editor of Boing Boing
Author, Down and Out in the Magic Kingdom
and Someone Comes to Town, Someone Leaves Town
Trang 5Praise for other Head First books
“I received the book yesterday and started to read it and I couldn’t stop This is definitely très ‘cool.’ It
is fun, but they cover a lot of ground and they are right to the point I’m really impressed.”
— Erich Gamma, IBM Distinguished Engineer, and co-author of Design Patterns
“One of the funniest and smartest books on software design I’ve ever read.”
— Aaron LaBerge, VP Technology, ESPN.com
“What used to be a long trial and error learning process has now been reduced neatly into an engaging
paperback.”
— Mike Davidson, CEO, Newsvine, Inc.
“Elegant design is at the core of every chapter here, each concept conveyed with equal doses of
pragmatism and wit.”
— Ken Goldstein, Executive Vice President, Disney Online
“I ♥ Head First HTML with CSS & XHTML—it teaches you everything you need to learn in a ‘fun coated’
format.”
— Sally Applin, UI Designer and Artist
“Usually when reading through a book or article on design patterns, I’d have to occasionally stick myself
in the eye with something just to make sure I was paying attention Not with this book Odd as it may
sound, this book makes learning about design patterns fun
“While other books on design patterns are saying ‘Buehler… Buehler… Buehler…’ this book is on the
float belting out ‘Shake it up, baby!’”
— Eric Wuehler
“I literally love this book In fact, I kissed this book in front of my wife.”
— Satish Kumar
Trang 6you are here 4 405
the index
starting and stopping, 316–317
volume, adjusting, 336–345
WAV files for, 221, 223
source code (see code)
spaces (see white space)
split() method, strings, 121–124, 144, 161–162, 175
SQL, 170 (see also database)
square brackets ([])
creating arrays, 132, 134
enclosing index of array, 132
enclosing index of string, 42
enclosing key for hash, 153
stack, 104
stack frame, 105, 111
Starbuzz Coffee example, 38–74, 78–110
coffee supplies, maintaining, 78–91
discount price, finding in HTML, 50–59
health club discounts, calculating, 204–213
low price, checking for, 60–74
order messages, sending to Twitter, 92–110
price, extracting from HTML, 38–49
startswith() method, strings, 56
Stellman, Andrew (Head First C#), 388
storage of data, 129–130
storeroom example, 294–310
strings, 41–42, 48, 75
ending substring, checking, 56
formatting, 180–184, 186, 214
lowercase, converting to, 56
methods for, 55–56
offset value (index) of, 42
removing white space from, 56
replacing substrings in, 56
searching for substrings in, 52–58
splitting at spaces, 121–124
splitting at specified character, 161–162
starting substring, checking, 56 substrings of, 43–46, 48, 49 uppercase, converting to, 54, 56 web pages as, 49
StringVar() variable, 278, 280, 292 strip() method, strings, 56
substrings, 48 length of, 49 searching for, in strings, 52–58 specifying, 43–46, 49
Surf-A-Thon example, 114–143, 146–174 highest score, calculating, 114–125 names, matching to scores, 142–143, 146–157 score data, extracting from database, 169–174 score data, extracting from formatted file, 160–167 scores, sorting, 136–141, 158–159
three highest scores, calculating, 126–135
T
tabs in code, 22 testing, automated, 389
text (see strings)
text boxes, 248 Text() widget, 261, 269, 292 creating, 266–267 methods for, 263 third-party libraries (packages), 220, 223 threads, 394
time() function, time library, 70 time library, 68–73
timezone() function, time library, 70 Tk() app, 234, 255
Trang 7406 Index
the index
tkinter library, 233–236, 238, 255, 341
toggle switch (see Checkbutton() widget)
transaction file, 179–184, 188–191
true value, 14
try statement, 298–300, 311
TVN example, 169–174 (see also game show example)
Twitter, sending messages to, 93–98, 101
TypeError message, 63–64
types (see datatypes)
U
Unicode character encoding system, 394
unittest module, 389
upper() method, strings, 54, 56
uppercase, converting strings to, 54
urllib.request library, 69
urlopen() function, 49
V
ValueError message, 119–120
variables, 4, 35
collections of (see data structures)
control variables, 278
global variables, 108–109, 244
local variables, 105, 106, 111
scope of, 104–108, 111
vi editor, 395
view, 277 (see also widgets) visual toggle (see Checkbutton() widget)
volume, adjusting, 336–345
W
wait_finish() function, 221, 223 WAV files, 221, 223
web pages, as strings, 49 West, Dave (Head First Object-Oriented Analysis & Design), 392
while loop, 29–33, 61–65 white space
in code, 22 removing from strings, 56 specifying in format strings, 182 splitting strings at, 121–124 widgets
Button() widget, 234–236, 239–244, 245, 255 choosing, 341
compared to objects, 368
for data entry (see data entry widgets)
event loop for, 255 Frame() widget, 364, 373, 383 grouping, 363–364
Label() widget, 248–253, 255 list of, 248
positioning, 235–238 Window Manager, 348 Window Manager events, 319–324, 326–327 WM_DELETE_WINDOW message, 322 WM_SAVE_YOURSELF message, 322 WM_TAKE_FOCUS message, 322