Python for Everyone

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Cay Horstmann's Python for Everyone provides readers with step-by-step guidance, a feature that is immensely helpful for building confidence and providing an outline for the task at hand. “Problem Solving” sections stress the importance of design and planning while “How To” guides help students with common programming tasks. Photographs present visual analogies that explain the nature and behavior of computer concepts. Step-by-step figures illustrate complex program operations, while syntax boxes and example tables present a variety of typical and special cases in a compact format. This book contains a substantial number of self-check questions at the end of each section. “Practice It” pointers suggest exercises to try after each section. Python for Everyone presents the essentials in digestible chunks, with separate notes that go deeper into good practices or language features when the reader is ready for the additional information. You will not find artificial over-simplifications that give an illusion of knowledge.

Author(s): Cay S. Horstmann, Rance D. Necaise
Edition: 1
Publisher: Wiley
Year: 2013

Language: English
Pages: 633

Title Page......Page 3
Copyright page......Page 4
Preface......Page 7
A Tour of the Book......Page 8
A Walkthrough of the Learning Aids......Page 10
Acknowledgments......Page 14
Table of Contents......Page 15
1 Introduction......Page 25
1.1 Computer Programs......Page 26
1.2 The Anatomy of a Computer......Page 27
1.3 The Python Programming Language......Page 29
1.4 Becoming Familiar with Your Programming Environment......Page 30
1.5 Analyzing Your First Program......Page 35
1.6 Errors......Page 38
1.7 Problem Solving: Algorithm Design......Page 40
2 Programming with Numbers and Strings......Page 53
2.1.1 Defining Variables......Page 54
2.1.2 Number Types......Page 56
2.1.3 Variable Names......Page 57
2.1.4 Constants......Page 58
2.1.5 Comments......Page 59
2.2.1 Basic Arithmetic Operations......Page 61
2.2.2 Powers......Page 62
2.2.3 Floor Division and Remainder......Page 63
2.2.4 Calling Functions......Page 64
2.2.5 Mathematical Functions......Page 65
2.3 Problem Solving: First Do It By Hand......Page 69
2.4.1 The String Type......Page 72
2.4.2 Concatenation and Repetition......Page 73
2.4.4 Strings and Characters......Page 74
2.4.5 String Methods......Page 76
2.5 Input and Output......Page 78
2.5.1 User Input......Page 79
2.5.3 Formatted Output......Page 80
2.6 Graphics: Simple Drawings......Page 89
3 Decisions......Page 115
3.1 The if Statement......Page 116
3.2 Relational Operators......Page 121
3.3 Nested Branches......Page 130
3.4 Multiple Alternatives......Page 133
3.5 Problem Solving: Flowcharts......Page 136
3.6 Problem Solving: Test Cases......Page 140
3.7 Boolean Variables and Operators......Page 142
3.8 Analyzing Strings......Page 148
3.9 Application: Input Validation......Page 151
4 Loops......Page 179
4.1 The while Loop......Page 180
4.2 Problem Solving: Hand-Tracing......Page 186
4.3 Application: Processing Sentinel Values......Page 190
4.4 Problem Solving: Storyboards......Page 194
4.5.1 Sum and Average Value......Page 197
4.5.4 Maximum and Minimum......Page 198
4.5.5 Comparing Adjacent Values......Page 199
4.6 The for Loop......Page 201
4.7 Nested Loops......Page 208
4.8.2 Finding All Matches......Page 214
4.8.4 Validating a String......Page 215
4.8.5 Building a New String......Page 216
4.9.1 Generating Random Numbers......Page 218
4.9.2 Simulating Die Tosses......Page 219
4.9.3 The Monte Carlo Method......Page 220
5 Functions......Page 243
5.1 Functions as Black Boxes......Page 244
5.2.1 Implementing a Function......Page 246
5.2.2 Testing a Function......Page 247
5.2.3 Programs that Contain Functions......Page 248
5.3 Parameter Passing......Page 250
5.4 Return Values......Page 253
5.5 Functions Without Return Values......Page 261
5.6 Problem Solving: Reusable Functions......Page 263
5.7 Problem Solving: Stepwise Refinement......Page 266
5.8 Variable Scope......Page 275
5.9 Recursive Functions (Optional)......Page 282
6 Lists......Page 301
6.1.1 Creating Lists......Page 302
6.1.2 Accessing List Elements......Page 303
6.1.3 Traversing Lists......Page 304
6.1.4 List References......Page 305
6.2.2 Inserting an Element......Page 308
6.2.3 Finding an Element......Page 309
6.2.4 Removing an Element......Page 310
6.2.7 Sum, Maximum, Minimum, and Sorting......Page 311
6.2.8 Copying Lists......Page 312
6.3 Common List Algorithms......Page 314
6.3.3 Element Separators......Page 315
6.3.5 Linear Search......Page 316
6.3.7 Removing Matches......Page 317
6.3.8 Swapping Elements......Page 318
6.3.9 Reading Input......Page 319
6.4 Using Lists with Functions......Page 321
6.5 Problem Solving: Adapting Algorithms......Page 327
6.6 Problem Solving: Discovering Algorithms by Manipulating Physical Objects......Page 334
6.7.1 Creating Tables......Page 338
6.7.2 Accessing Elements......Page 339
6.7.4 Computing Row and Column Totals......Page 340
6.7.5 Using Tables with Functions......Page 341
7 Files and Exceptions......Page 365
7.1.1 Opening a File......Page 366
7.1.2 Reading from a File......Page 367
7.1.4 A File Processing Example......Page 368
7.2.1 Iterating over the Lines of a File......Page 370
7.2.2 Reading Words......Page 372
7.2.3 Reading Characters......Page 374
7.2.4 Reading Records......Page 375
7.3 Command Line Arguments......Page 381
7.4.1 Reading and Writing Binary Files......Page 392
7.4.2 Random Access......Page 393
7.4.3 Image Files......Page 394
7.4.4 Reading and Displaying BMP Images......Page 395
7.4.5 Processing Image Files......Page 398
7.5.1 Raising Exceptions......Page 401
7.5.2 Handling Exceptions......Page 402
7.5.3 The finally Clause......Page 404
7.6 Application: Handling Input Errors......Page 407
8 Sets and Dictionaries......Page 427
8.1 Sets......Page 428
8.2 Dictionaries......Page 438
8.2.1 Creating Dictionaries......Page 439
8.2.3 Adding and Modifying Items......Page 440
8.2.4 Removing Items......Page 441
8.2.5 Traversing a Dictionary......Page 442
8.3.1 A Dictionary of Sets......Page 448
8.3.2 A Dictionary of Lists......Page 451
9 Objects and Classes......Page 467
9.1 Object-Oriented Programming......Page 468
9.2 Implementing a Simple Class......Page 470
9.3 Specifying the Public Interface of a Class......Page 474
9.4 Designing the Data Representation......Page 476
9.5 Constructors......Page 478
9.6 Implementing Methods......Page 481
9.7 Testing a Class......Page 485
9.8 Problem Solving: Tracing Objects......Page 493
9.9.1 Keeping a Total......Page 496
9.9.3 Collecting Values......Page 497
9.9.5 Modeling Objects with Distinct States......Page 498
9.9.6 Describing the Position of an Object......Page 499
9.10.1 Shared References......Page 502
9.10.3 The self Reference......Page 504
9.10.4 The Lifetime of Objects......Page 505
9.11.1 Fraction Class Design......Page 506
9.11.2 The Constructor......Page 507
9.11.3 Special Methods......Page 508
9.11.4 Arithmetic Operations......Page 510
9.11.5 Logical Operations......Page 511
10 Inheritance......Page 531
10.1 Inheritance Hierarchies......Page 532
10.2 Implementing Subclasses......Page 537
10.3 Calling the Superclass Constructor......Page 541
10.4 Overriding Methods......Page 545
10.5 Polymorphism......Page 548
10.6 Application: A Geometric Shape Class Hierarchy......Page 562
10.6.1 The Base Class......Page 563
10.6.2 Basic Shapes......Page 565
10.6.3 Groups of Shapes......Page 568
11 Recursion......Page 579
11.1 Triangle Numbers Revisited......Page 580
11.2 Problem Solving: Thinking Recursively......Page 584
11.3 Recursive Helper Functions......Page 589
11.4 The Efficiency of Recursion......Page 590
11.5 Permutations......Page 595
11.6 Backtracking......Page 598
11.7 Mutual Recursion......Page 607
12 Sorting and Searching......Page 621
12.1 Selection Sort......Page 622
12.2 Profiling the Selection Sort Algorithm......Page 624
12.3 Analyzing the Performance of the Selection Sort Algorithm......Page 626
12.4 Merge Sort......Page 630
12.5 Analyzing the Merge Sort Algorithm......Page 633
12.6 Searching......Page 637
12.6.1 Linear Search......Page 638
12.6.2 Binary Search......Page 639
12.7.1 Linear Time......Page 641
12.7.2 Quadratic Time......Page 642
12.7.3 The Triangle Pattern......Page 643
12.7.4 Logarithmic Time......Page 645
Appendix A The Basic Latin and Latin - 1 Subsets of Unicode......Page 659
Appendix B Python Operator Summary......Page 662
Appendix C Python Reserved Word Summary......Page 664
Built-in Functions......Page 666
Built-in Classes......Page 670
File Input/Output......Page 676
math Module......Page 678
os.path Module......Page 680
time Module......Page 681
graphics Module......Page 682
Binary Numbers......Page 687
Bit and Shift Operations......Page 689
Glossary......Page 691
Index......Page 699
Illustration Credits......Page 719