Download Learning Python 4th edition Mark Lutz ebook All Chapters PDF
Download Learning Python 4th edition Mark Lutz ebook All Chapters PDF
com
https://ebookname.com/product/learning-python-4th-edition-
mark-lutz/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/learning-python-third-edition-mark-lutz/
ebookname.com
https://ebookname.com/product/programming-python-4th-edition-mark-
lutz/
ebookname.com
https://ebookname.com/product/python-pocket-reference-4th-ed-edition-
mark-lutz/
ebookname.com
https://ebookname.com/product/introduction-to-operations-research-7th-
bk-cdr-edition-sheldon-m-ross/
ebookname.com
Demystifying Global Macroeconomics 3rd Edition Edition
John E. Marthinsen
https://ebookname.com/product/demystifying-global-macroeconomics-3rd-
edition-edition-john-e-marthinsen/
ebookname.com
https://ebookname.com/product/presenting-your-findings-a-practical-
guide-for-creating-tables-6th-edition-adelheid-a-m-nicol/
ebookname.com
https://ebookname.com/product/prophecy-and-reason-the-dutch-
collegiants-in-the-early-enlightenment-andrew-cooper-fix/
ebookname.com
https://ebookname.com/product/the-blackwell-companion-to-social-
work-4th-edition-martin-davies/
ebookname.com
https://ebookname.com/product/contemporary-cognitive-therapy-theory-
research-and-practice-1st-edition-robert-l-leahy-phd/
ebookname.com
An Enquiry into Bukharan Qadimism Mirza Salim bik 1st
Edition Franz Wennberg
https://ebookname.com/product/an-enquiry-into-bukharan-qadimism-mirza-
salim-bik-1st-edition-franz-wennberg/
ebookname.com
Learning Python
FOURTH EDITION
Learning Python
Mark Lutz
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
March 1999: First Edition.
December 2003: Second Edition.
October 2007: Third Edition.
September 2009: Fourth Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Learning Python, the image of a wood rat, and related trade dress are trademarks
of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-0-596-15806-4
[M]
1252944666
To Vera.
You are my life.
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
vii
Chapter Summary 18
Test Your Knowledge: Quiz 19
Test Your Knowledge: Answers 19
Table of Contents | ix
User-Defined Classes 101
And Everything Else 102
Chapter Summary 103
Test Your Knowledge: Quiz 103
Test Your Knowledge: Answers 104
x | Table of Contents
7. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
String Literals 157
Single- and Double-Quoted Strings Are the Same 158
Escape Sequences Represent Special Bytes 158
Raw Strings Suppress Escapes 161
Triple Quotes Code Multiline Block Strings 162
Strings in Action 163
Basic Operations 164
Indexing and Slicing 165
String Conversion Tools 169
Changing Strings 171
String Methods 172
String Method Examples: Changing Strings 174
String Method Examples: Parsing Text 176
Other Common String Methods in Action 177
The Original string Module (Gone in 3.0) 178
String Formatting Expressions 179
Advanced String Formatting Expressions 181
Dictionary-Based String Formatting Expressions 182
String Formatting Method Calls 183
The Basics 184
Adding Keys, Attributes, and Offsets 184
Adding Specific Formatting 185
Comparison to the % Formatting Expression 187
Why the New Format Method? 190
General Type Categories 193
Types Share Operation Sets by Categories 194
Mutable Types Can Be Changed In-Place 194
Chapter Summary 195
Test Your Knowledge: Quiz 195
Test Your Knowledge: Answers 196
Table of Contents | xi
More Dictionary Methods 211
A Languages Table 212
Dictionary Usage Notes 213
Other Ways to Make Dictionaries 216
Dictionary Changes in Python 3.0 217
Chapter Summary 223
Test Your Knowledge: Quiz 224
Test Your Knowledge: Answers 224
Table of Contents | xv
17. Scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Python Scope Basics 407
Scope Rules 408
Name Resolution: The LEGB Rule 410
Scope Example 411
The Built-in Scope 412
The global Statement 414
Minimize Global Variables 415
Minimize Cross-File Changes 416
Other Ways to Access Globals 418
Scopes and Nested Functions 419
Nested Scope Details 419
Nested Scope Examples 419
The nonlocal Statement 425
nonlocal Basics 425
nonlocal in Action 426
Why nonlocal? 429
Chapter Summary 432
Test Your Knowledge: Quiz 433
Test Your Knowledge: Answers 434
Part V. Modules
xx | Table of Contents
Classes Versus Dictionaries 639
Chapter Summary 641
Test Your Knowledge: Quiz 641
Test Your Knowledge: Answers 641
Twisted Eglantine.
Illustrated. Ornamental Cloth,
$1.50.
This is the history of a love
affair of a famous English beau in
the time of George IV. The
heroine is a ravishingly beautiful
country girl, with whom the beau
becomes infatuated. By the aid of
her country lover she is rescued
from the wiles of the fashionable
dandy, and his schemes are
thwarted.
“The story is on a high plane;
it is a romance which is entirely
free from the melodramatic
quality; in a word, a novel that
will enhance the author’s
reputation as a writer of fiction of
far more than ordinary
attainments.”—Brooklyn Eagle.
“He has presented to us the
only living beau we have met this
many a year; and where so many
hundreds have failed, to say this
is the highest compliment we can
pay his book.”—The Outlook.
Wild Justice.
Illustrated. Ornamental Cloth,
$1.50.
“Lloyd Osbourne’s stories of
the South Sea Islands are second
only to Stevenson’s on the same
theme. ‘Wild Justice’ is a volume
of these short stories, beginning
with that strong and haunting
tale, ‘The Renegade.’ These are
stories which will bear reading
more than once. They have an
atmosphere that it is restful to
breathe, once in a while, to the
dwellers in cities and the toilers of
these Northern lands where life is
such a stern affair.”—Denver Post.
“Mr. Lloyd Osbourne’s nine
stories of the South Sea Islands
(‘Wild Justice’) are told with a
Kiplingesque vigor, and well
illustrate their title. All are
eminently readable—not
overweighted with tragedy, as is
the wont of tales that deal with
the remote regions of the
earth.”—New York Times.
“Mr. Osbourne in ‘Wild Justice’
has given us a series of stories
about the Samoan Islands and
their islanders and their white
invaders, visitors and conquerors
which are vivid with humor and
pathos.”—New York Herald.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.