𝔖 Scriptorium
✦   LIBER   ✦

📁

Learning Python, 3rd Edition

✍ Scribed by Safari, an O'Reilly Media Company.; Lutz, Mark


Publisher
O'Reilly Media
Year
2007
Tongue
English
Leaves
748
Edition
3rd edition
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Portable, powerful, and a breeze to use, Python is ideal for both standalone programs and scripting applications. With this hands-on book, you can master the fundamentals of the core Python language quickly and efficiently, whether you're new to programming or just new to Python. Once you finish, you will know enough about the language to use it in any application domain you choose.

Learning Pythonis based on material from author Mark Lutz's popular training courses, which he's taught over the past decade. Each chapter is a self-contained lesson that helps you thoroughly understand a key component of Python before you continue. Along with plenty of annotated examples, illustrations, and chapter summaries, every chapter also containsBrain Builder, a unique section with practical exercises and review quizzes that let you practice new skills and test your understanding as you go.

This book covers:


Types and Operations -- Python's major built-in object types in depth: numbers, lists, dictionaries, and more


Statements and Syntax -- the code you type to create and process objects in Python, along with Python's general syntax model


Functions -- Python's basic procedural tool for structuring and reusing code


Modules -- packages of statements, functions, and other tools organized into larger components


Classes and OOP -- Python's optional object-oriented programming tool for structuring code for customization and reuse


Exceptions and Tools -- exception handling model and statements, plus a look at development tools for writing larger programs
Learning Pythongives you a deep and complete understanding of the language that will help you comprehend any application-level examples of Python that you later encounter. If you're ready to discover what Google and YouTube see in Python, this book is the best way to get started.

✦ Table of Contents


Learning Python, Third Edition......Page 1
Table of Contents......Page 8
This Edition’s Python Language Changes......Page 30
This Edition’s Python Training Changes......Page 31
This Edition’s Structural Changes......Page 32
This Book’s Prerequisites......Page 33
This Book’s Scope and Other Books......Page 34
This Book’s Style and Structure......Page 35
About the Programs in This Book......Page 37
Preparing for Python 3.0......Page 38
Using Code Examples......Page 41
Font Conventions......Page 42
Acknowledgments......Page 43
Part I......Page 46
Why Do People Use Python?......Page 48
Developer Productivity......Page 50
Is Python a “Scripting Language”?......Page 51
OK, but What’s the Downside?......Page 52
Who Uses Python Today?......Page 53
GUIs......Page 54
Component Integration......Page 55
Numeric and Scientific Programming......Page 56
It’s Object Oriented......Page 57
It’s Portable......Page 58
It’s Powerful......Page 59
It’s Easy to Use......Page 60
It’s Named After Monty Python......Page 62
How Does Python Stack Up to Language X?......Page 63
Chapter Summary......Page 64
Quiz Answers......Page 65
Introducing the Python Interpreter......Page 67
The Programmer’s View......Page 69
Byte code compilation......Page 70
Performance implications......Page 71
Execution Model Variations......Page 72
Jython......Page 73
The Psyco just-in-time compiler......Page 74
The Shedskin C++ translator......Page 75
Frozen Binaries......Page 76
Chapter Summary......Page 77
Quiz Answers......Page 78
Interactive Coding......Page 79
System Command Lines and Files......Page 82
Using Command Lines and Files......Page 85
Unix Executable Scripts (#!)......Page 86
Clicking Icons on Windows......Page 87
The raw_input Trick......Page 89
Module Imports and Reloads......Page 90
The Grander Module Story: Attributes......Page 92
import and reload Usage Notes......Page 94
The IDLE User Interface......Page 95
IDLE Basics......Page 96
Using IDLE......Page 97
Other IDEs......Page 99
Frozen Binary Executables......Page 101
Future Possibilities?......Page 102
Chapter Summary......Page 103
Quiz Answers......Page 104
Part II......Page 108
Introducing Python Object Types......Page 110
Why Use Built-in Types?......Page 111
Python’s Core Data Types......Page 112
Numbers......Page 113
Strings......Page 114
Sequence Operations......Page 115
Immutability......Page 116
Type-Specific Methods......Page 117
Getting Help......Page 118
Other Ways to Code Strings......Page 119
Lists......Page 120
Type-Specific Operations......Page 121
Nesting......Page 122
List Comprehensions......Page 123
Mapping Operations......Page 124
Nesting Revisited......Page 125
Sorting Keys: for Loops......Page 126
Iteration and Optimization......Page 128
Missing Keys: if Tests......Page 129
Files......Page 130
Other File-Like Tools......Page 131
Other Core Types......Page 132
User-Defined Classes......Page 133
And Everything Else......Page 134
Chapter Summary......Page 135
Quiz Answers......Page 136
Python Numeric Types......Page 138
Numeric Literals......Page 139
Built-in Numeric Tools and Extensions......Page 140
Python Expression Operators......Page 141
Mixed Types Are Converted Up......Page 142
Preview: Operator Overloading......Page 143
Variables and Basic Expressions......Page 144
Numeric Display Formats......Page 145
Division: Classic, Floor, and True......Page 147
Long Integers......Page 148
Complex Numbers......Page 149
Hexadecimal and Octal Notation......Page 150
Other Built-in Numeric Tools......Page 151
Decimal Numbers......Page 152
Sets......Page 153
Booleans......Page 154
Chapter Summary......Page 155
Quiz Answers......Page 156
Variables, Objects, and References......Page 157
Types Live with Objects, Not Variables......Page 159
Objects Are Garbage-Collected......Page 160
Shared References......Page 161
Shared References and In-Place Changes......Page 163
Shared References and Equality......Page 164
Chapter Summary......Page 166
Quiz Answers......Page 167
Strings......Page 168
String Literals......Page 169
Escape Sequences Represent Special Bytes......Page 170
Raw Strings Suppress Escapes......Page 172
Triple Quotes Code Multiline Block Strings......Page 174
Unicode Strings Encode Larger Character Sets......Page 175
Basic Operations......Page 177
Indexing and Slicing......Page 178
Extended slicing: the third limit......Page 180
String Conversion Tools......Page 181
Character code conversions......Page 183
Changing Strings......Page 184
String Formatting......Page 185
Advanced String Formatting......Page 186
Dictionary-Based String Formatting......Page 187
String Methods......Page 188
String Method Examples: Changing Strings......Page 189
String Method Examples: Parsing Text......Page 191
Other Common String Methods in Action......Page 192
The Original string Module......Page 193
Types Share Operation Sets by Categories......Page 194
Chapter Summary......Page 195
Quiz Answers......Page 196
Lists......Page 197
Basic List Operations......Page 199
Indexing, Slicing, and Matrixes......Page 200
Index and slice assignments......Page 201
List method calls......Page 202
Other common list operations......Page 204
Dictionaries......Page 205
Dictionaries in Action......Page 206
Basic Dictionary Operations......Page 207
More Dictionary Methods......Page 208
A Languages Table......Page 210
Using dictionaries to simulate flexible lists......Page 211
Avoiding missing-key errors......Page 212
Using dictionaries as “records”......Page 213
Other ways to make dictionaries......Page 214
Chapter Summary......Page 215
Quiz Answers......Page 216
Tuples......Page 217
Tuples in Action......Page 218
Conversions and immutability......Page 219
Why Lists and Tuples?......Page 220
Opening Files......Page 221
Using Files......Page 222
Storing and parsing Python objects in files......Page 223
Storing native Python objects with pickle......Page 225
Storing and parsing packed binary data in files......Page 226
Type Categories Revisited......Page 227
Object Flexibility......Page 228
References Versus Copies......Page 229
Comparisons, Equality, and Truth......Page 231
The Meaning of True and False in Python......Page 233
Python’s Type Hierarchies......Page 234
Assignment Creates References, Not Copies......Page 236
Repetition Adds One Level Deep......Page 237
Chapter Summary......Page 238
Quiz Answers......Page 240
Part III......Page 244
Python Program Structure Revisited......Page 246
Python’s Statements......Page 247
A Tale of Two ifs......Page 248
End of line is end of statement......Page 249
End of indentation is end of block......Page 250
Why Indentation Syntax?......Page 251
Statement rule special cases......Page 253
Block rule special case......Page 254
A Simple Interactive Loop......Page 255
Doing Math on User Inputs......Page 256
Handling Errors by Testing Inputs......Page 257
Handling Errors with try Statements......Page 258
Nesting Code Three Levels Deep......Page 259
Chapter Summary......Page 260
Quiz Answers......Page 261
Assignment Statements......Page 262
Assignment Statement Forms......Page 263
Sequence Assignments......Page 264
Advanced sequence assignment patterns......Page 265
Multiple-target assignment and shared references......Page 267
Augmented Assignments......Page 268
Variable Name Rules......Page 270
Names have no type, but objects do......Page 272
Expression Statements......Page 273
print Statements......Page 274
The Python “Hello World” Program......Page 275
Redirecting the Output Stream......Page 276
The print >> file Extension......Page 277
Chapter Summary......Page 279
Quiz Answers......Page 280
General Format......Page 281
Multiway Branching......Page 282
Python Syntax Rules......Page 284
Block Delimiters......Page 285
Statement Delimiters......Page 286
A Few Special Cases......Page 287
Truth Tests......Page 288
The if/else Ternary Expression......Page 289
Chapter Summary......Page 291
Quiz Answers......Page 292
while Loops......Page 293
Examples......Page 294
General Loop Format......Page 295
continue......Page 296
else......Page 297
More on the loop else clause......Page 298
General Format......Page 299
Other data types......Page 301
Nested for loops......Page 302
Iterators: A First Look......Page 303
File Iterators......Page 305
Other Built-in Type Iterators......Page 307
Other Iteration Contexts......Page 308
User-Defined Iterators......Page 309
Counter Loops: while and range......Page 310
Nonexhaustive Traversals: range......Page 311
Changing Lists: range......Page 312
Parallel Traversals: zip and map......Page 313
Dictionary construction with zip......Page 315
Generating Both Offsets and Items: enumerate......Page 316
List Comprehension Basics......Page 317
Using List Comprehensions on Files......Page 318
Extended List Comprehension Syntax......Page 319
Chapter Summary......Page 320
Quiz Answers......Page 321
Python Documentation Sources......Page 323
The dir Function......Page 324
Docstrings: _doc......Page 325
User-defined docstrings......Page 326
Built-in docstrings......Page 327
PyDoc: The help Function......Page 328
PyDoc: HTML Reports......Page 330
Web Resources......Page 334
Published Books......Page 335
Common Coding Gotchas......Page 336
Chapter Summary......Page 338
Quiz Answers......Page 339
Part IV......Page 342
Function Basics......Page 344
Coding Functions......Page 345
def Statements......Page 347
A First Example: Definitions and Calls......Page 348
Calls......Page 349
Polymorphism in Python......Page 350
Calls......Page 351
Polymorphism Revisited......Page 352
Chapter Summary......Page 353
Quiz Answers......Page 354
Scope Rules......Page 355
Python Scope Basics......Page 356
Name Resolution: The LEGB Rule......Page 357
The Built-in Scope......Page 359
The global Statement......Page 361
Minimize Global Variables......Page 362
Minimize Cross-File Changes......Page 363
Other Ways to Access Globals......Page 364
Nested Scope Details......Page 365
Factory functions......Page 366
Retaining enclosing scopes’ state with defaults......Page 368
Scopes versus defaults with loop variables......Page 369
Passing Arguments......Page 371
Arguments and Shared References......Page 372
Simulating Output Parameters......Page 374
Special Argument-Matching Modes......Page 375
Keywords......Page 377
Arbitrary Arguments Examples......Page 378
Unpacking arguments......Page 379
Combining Keywords and Defaults......Page 380
Full credit......Page 381
Bonus points......Page 382
A More Useful Example: General Set Functions......Page 383
Argument Matching: The Gritty Details......Page 384
Chapter Summary......Page 385
Quiz Answers......Page 388
lambda Expressions......Page 389
Why Use lambda?......Page 391
How (Not) to Obfuscate Your Python Code......Page 392
Nested lambdas and Scopes......Page 393
The apply Built-in......Page 395
apply-Like Call Syntax......Page 396
Mapping Functions over Sequences: map......Page 397
Functional Programming Tools: filter and reduce......Page 398
List Comprehension Basics......Page 400
Adding Tests and Nested Loops......Page 401
List Comprehensions and Matrixes......Page 403
Iterators Revisited: Generators......Page 405
Generator Function Example......Page 407
Iterators and Built-in Types......Page 409
Generator Expressions: Iterators Meet List Comprehensions......Page 410
Timing Iteration Alternatives......Page 411
Function Design Concepts......Page 414
Functions Are Objects: Indirect Calls......Page 415
Function Gotchas......Page 416
Local Names Are Detected Statically......Page 417
Defaults and Mutable Objects......Page 418
Chapter Summary......Page 420
Quiz Answers......Page 422
Part V......Page 428
Why Use Modules?......Page 430
Python Program Architecture......Page 431
Imports and Attributes......Page 432
How Imports Work......Page 434
The module search path......Page 435
The sys.path list......Page 437
Advanced module selection concepts......Page 438
3. Run It......Page 439
Chapter Summary......Page 440
Quiz Answers......Page 442
Module Creation......Page 443
The import Statement......Page 444
Imports Happen Only Once......Page 445
import and from Are Assignments......Page 446
import and from Equivalence......Page 447
Potential Pitfalls of the from Statement......Page 448
Module Namespaces......Page 449
Files Generate Namespaces......Page 450
Attribute Name Qualification......Page 451
Imports Versus Scopes......Page 452
Namespace Nesting......Page 453
Reloading Modules......Page 454
reload Basics......Page 455
reload Example......Page 456
Chapter Summary......Page 457
Quiz Answers......Page 459
Package Import Basics......Page 460
Package
init.py Files......Page 461
Package Import Example......Page 463
from Versus import with Packages......Page 464
Why Use Package Imports?......Page 465
A Tale of Three Systems......Page 466
Chapter Summary......Page 469
Quiz Answers......Page 470
Minimizing from * Damage: _X and
all......Page 471
Enabling Future Language Features......Page 472
Mixed Usage Modes:
name and main......Page 473
Unit Tests with
name......Page 474
Changing the Module Search Path......Page 475
Relative Import Syntax......Page 476
Why Relative Imports?......Page 477
Module Design Concepts......Page 479
Modules Are Objects: Metaprograms......Page 480
Statement Order Matters in Top-Level Code......Page 482
Importing Modules by Name String......Page 483
from Copies Names but Doesn’t Link......Page 484
reload May Not Impact from Imports......Page 485
reload, from, and Interactive Testing......Page 486
reload Isn’t Applied Transitively......Page 487
Recursive from Imports May Not Work......Page 488
Chapter Summary......Page 489
Quiz Answers......Page 490
Part VI......Page 494
OOP: The Big Picture......Page 496
Why Use Classes?......Page 497
Attribute Inheritance Search......Page 498
Classes and Instances......Page 500
Coding Class Trees......Page 501
OOP Is About Code Reuse......Page 504
Chapter Summary......Page 507
Quiz Answers......Page 508
Classes Generate Multiple Instance Objects......Page 510
Instance Objects Are Concrete Items......Page 511
A First Example......Page 512
Classes Are Customized by Inheritance......Page 514
A Second Example......Page 515
Classes Are Attributes in Modules......Page 516
Classes Can Intercept Python Operators......Page 517
A Third Example......Page 519
Why Use Operator Overloading?......Page 520
The World’s Simplest Python Class......Page 521
Chapter Summary......Page 523
Quiz Answers......Page 524
General Form......Page 526
Example......Page 527
Methods......Page 529
Example......Page 530
Inheritance......Page 531
Attribute Tree Construction......Page 532
Specializing Inherited Methods......Page 533
Class Interface Techniques......Page 534
Abstract Superclasses......Page 535
Operator Overloading......Page 536
Common Operator Overloading Methods......Page 537
getitem and iter Implement Iteration......Page 538
User-Defined Iterators......Page 539
Multiple iterators on one object......Page 541
getattr and setattr Catch Attribute References......Page 543
Emulating Privacy for Instance Attributes......Page 544
repr and str Return String Representations......Page 545
call Intercepts Calls......Page 547
Function Interfaces and Callback-Based Code......Page 548
del_ Is a Destructor......Page 550
The “Zen” of Python Namespaces: Assignments Classify Names......Page 551
Namespace Dictionaries......Page 553
Namespace Links......Page 556
A More Realistic Example......Page 557
Chapter Summary......Page 560
Quiz Answers......Page 561
Python and OOP......Page 563
Classes As Records......Page 564
OOP and Inheritance: “Is-a” Relationships......Page 566
OOP and Composition: “Has-a” Relationships......Page 568
Stream Processors Revisited......Page 569
OOP and Delegation......Page 572
Multiple Inheritance......Page 574
Classes Are Objects: Generic Object Factories......Page 577
Why Factories?......Page 578
Methods Are Objects: Bound or Unbound......Page 579
Documentation Strings Revisited......Page 580
Chapter Summary......Page 582
Quiz Answers......Page 583
Extending Built-in Types......Page 584
Extending Types by Subclassing......Page 585
Name Mangling Overview......Page 588
Why Use Pseudoprivate Attributes?......Page 589
New-Style Classes......Page 590
Diamond Inheritance Change......Page 591
Explicit conflict resolution......Page 592
Instance slots......Page 594
Class properties......Page 595
Static and Class Methods......Page 597
Using Static and Class Methods......Page 599
Function Decorators......Page 601
Decorator Example......Page 603
Changing Class Attributes Can Have Side Effects......Page 604
Multiple Inheritance: Order Matters......Page 605
Methods, Classes, and Nested Scopes......Page 606
“Overwrapping-itis”......Page 608
Chapter Summary......Page 609
Quiz Answers......Page 610
Part VII......Page 618
Exception Basics......Page 620
Exception Roles......Page 621
Exception Handling: The Short Story......Page 622
The try/except/else Statement......Page 626
try Statement Clauses......Page 627
Example: Default Behavior......Page 630
Example: Catching Built-in Exceptions......Page 631
The try/finally Statement......Page 632
Example: Coding Termination Actions with try/finally......Page 633
Unified try/except/finally......Page 634
Combining finally and except by Nesting......Page 635
Unified try Example......Page 636
The raise Statement......Page 637
Example: Passing Extra Data with raise......Page 638
Example: Propagating Exceptions with raise......Page 639
Example: Trapping Constraints (but Not Errors)......Page 640
Basic Usage......Page 641
The Context Management Protocol......Page 643
Chapter Summary......Page 645
Quiz Answers......Page 646
Exception Objects......Page 647
String Exceptions Are Right Out!......Page 648
Class Exception Example......Page 649
Why Class Exceptions?......Page 651
Built-in Exception Classes......Page 654
Specifying Exception Text......Page 655
Example: Extra data with classes and strings......Page 656
General raise Statement Forms......Page 658
Chapter Summary......Page 660
Quiz Answers......Page 661
Nesting Exception Handlers......Page 662
Example: Syntactic Nesting......Page 664
Exceptions Aren’t Always Errors......Page 666
Debugging with Outer try Statements......Page 667
Running In-Process Tests......Page 668
What Should Be Wrapped......Page 669
Catching Too Much: Avoid Empty excepts......Page 670
Exception Gotchas......Page 672
String Exceptions Match by Identity, Not by Value......Page 673
Core Language Summary......Page 674
The Python Toolset......Page 675
Development Tools for Larger Projects......Page 676
Chapter Summary......Page 679
Quiz Answers......Page 680
Part VIII......Page 682
Where to Fetch Python......Page 684
Installation Steps......Page 685
Configuring Python......Page 686
Python Environment Variables......Page 687
DOS variables (Windows)......Page 689
Path files......Page 690
Part I, Getting Started......Page 691
Part II, Types and Operations......Page 693
Part III, Statements and Syntax......Page 699
Part IV, Functions......Page 701
Part V, Modules......Page 706
Part VI, Classes and OOP......Page 709
Part VII, Exceptions and Tools......Page 717
Index......Page 726

✦ Subjects


Computer Science;Programming;Science;Reference;Nonfiction;Technology;Computers;Technical;Coding;Textbooks;Software


📜 SIMILAR VOLUMES


Learning Python, 3rd Edition
✍ Mark Lutz 📂 Library 📅 1999 🏛 O'Reilly Media 🌐 English

About the Author Mark Lutz is the world leader in Python training, the author of Python's earliest and best-selling texts, and a pioneering figure in the Python community since 1992. He is also the author of O'Reilly's Programming Python, 3rd Edition and Python Pocket Reference, 3rd Edition. Mark

Python Machine Learning: Machine Learnin
✍ Raschka, Sebastian;Mirjalili, Vahid 📂 Library 📅 2019 🏛 Packt Publishing 🌐 English

Link to the GitHub Repository containing the code examples and additional material:<a target="_blank" rel="noopener nofollow" href="https://github.com/rasbt/python-machine-learning-book">https://github.com/rasbt/python-machi...</a><br /><br />Many of the most innovative breakthroughs and exciting ne

Python Machine Learning: Machine Learnin
✍ Raschka, Sebastian;Mirjalili, Vahid 📂 Library 📅 2019 🏛 Packt Publishing 🌐 English

Link to the GitHub Repository containing the code examples and additional material:<a target="_blank" rel="noopener nofollow" href="https://github.com/rasbt/python-machine-learning-book">https://github.com/rasbt/python-machi...</a><br /><br />Many of the most innovative breakthroughs and exciting ne