Think Python: How to Think Like a Computer Scientist. 3 Ed

Think Python: How to Think Like a Computer Scientist. 3 Ed

Think Python: How to Think Like a Computer Scientist. 3 Ed
Автор: Downey Allen
Дата выхода: 2024
Издательство: O’Reilly Media, Inc.
Количество страниц: 630
Размер файла: 2,3 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Preface....6

Who Is This Book For?....6

Goals of the Book....8

Navigating the Book....8

What’s New in the Third Edition?....10

Getting Started....11

Resources for Teachers....12

Conventions Used in This Book....13

Using Code Examples....14

O’Reilly Online Learning....15

How to Contact Us....15

Acknowledgments....16

1. Programming as a Way of Thinking....18

Arithmetic Operators....18

Expressions....22

Arithmetic Functions....23

Strings....26

Values and Types....29

Formal and Natural Languages....34

Debugging....35

Glossary....36

Exercises....38

2. Variables and Statements....43

Variables....43

State Diagrams....46

Variable Names....46

The import Statement....49

Expressions and Statements....50

The print Function....51

Arguments....53

Comments....57

Debugging....58

Glossary....60

Exercises....62

3. Functions....65

Defining New Functions....65

Parameters....67

Calling Functions....69

Repetition....72

Variables and Parameters Are Local....75

Stack Diagrams....76

Tracebacks....78

Why Functions?....80

Debugging....80

Glossary....81

Exercises....82

4. Functions and Interfaces....87

The jupyturtle Module....87

Making a Square....91

Encapsulation and Generalization....93

Approximating a Circle....98

Refactoring....100

Stack Diagram....104

A Development Plan....104

Docstrings....106

Debugging....107

Glossary....108

Exercises....109

5. Conditionals and Recursion....117

Integer Division and Modulus....117

Boolean Expressions....120

Logical Operators....123

if Statements....125

The else Clause....126

Chained Conditionals....127

Nested Conditionals....128

Recursion....130

Stack Diagrams for Recursive Functions....133

Infinite Recursion....135

Keyboard Input....136

Debugging....139

Glossary....141

Exercises....142

6. Return Values....152

Some Functions Have Return Values....152

And Some Have None....156

Return Values and Conditionals....158

Incremental Development....160

Boolean Functions....166

Recursion with Return Values....168

Leap of Faith....173

Fibonacci....174

Checking Types....175

Debugging....177

Glossary....180

Exercises....181

7. Iteration and Search....184

Loops and Strings....184

Reading the Word List....187

Updating Variables....190

Looping and Counting....192

The in Operator....194

Search....197

Doctest....199

Glossary....202

Exercises....203

8. Strings and Regular Expressions....211

A String Is a Sequence....211

String Slices....215

Strings Are Immutable....217

String Comparison....219

String Methods....220

Writing Files....221

Find and Replace....226

Regular Expressions....228

String Substitution....234

Debugging....237

Glossary....238

Exercises....239

9. Lists....243

A List Is a Sequence....243

Lists Are Mutable....245

List Slices....248

List Operations....250

List Methods....252

Lists and Strings....254

Looping Through a List....256

Sorting Lists....258

Objects and Values....259

Aliasing....261

List Arguments....263

Making a Word List....265

Debugging....268

Glossary....269

Exercises....270

10. Dictionaries....275

A Dictionary Is a Mapping....275

Creating Dictionaries....279

The in Operator....280

A Collection of Counters....285

Looping and Dictionaries....287

Lists and Dictionaries....289

Accumulating a List....290

Memos....293

Debugging....297

Glossary....298

Exercises....299

11. Tuples....305

Tuples Are Like Lists....305

But Tuples Are Immutable....310

Tuple Assignment....312

Tuples as Return Values....316

Argument Packing....318

Zip....321

Comparing and Sorting....326

Inverting a Dictionary....330

Debugging....332

Glossary....335

Exercises....335

12. Text Analysis and Generation....342

Unique Words....342

Punctuation....344

Word Frequencies....350

Optional Parameters....352

Dictionary Subtraction....354

Random Numbers....357

Bigrams....361

Markov Analysis....366

Generating Text....371

Debugging....373

Glossary....375

Exercises....376

Exercise....379

13. Files and Databases....380

Filenames and Paths....380

f-strings....385

YAML....388

Shelve....391

Storing Data Structures....396

Checking for Equivalent Files....400

Walking Directories....404

Debugging....407

Glossary....408

Exercises....410

14. Classes and Functions....414

Programmer-Defined Types....414

Attributes....416

Objects as Return Values....420

Objects Are Mutable....420

Copying....424

Pure Functions....426

Prototype and Patch....427

Design-First Development....432

Debugging....436

Glossary....438

Exercises....439

15. Classes and Methods....443

Defining Methods....443

Another Method....446

Static Methods....448

Comparing Time Objects....451

The __str__ Method....452

The __init__ Method....454

Operator Overloading....456

Debugging....457

Glossary....459

Exercises....460

16. Classes and Objects....463

Creating a Point....463

Creating a Line....467

Equivalence and Identity....472

Creating a Rectangle....474

Changing Rectangles....478

Deep Copy....482

Polymorphism....487

Debugging....489

Glossary....490

Exercises....491

17. Inheritance....493

Representing Cards....493

Card Attributes....497

Printing Cards....498

Comparing Cards....500

Decks....508

Printing the Deck....509

Add, Remove, Shuffle, and Sort....511

Parents and Children....515

Specialization....518

Debugging....521

Glossary....523

Exercises....524

18. Python Extras....534

Sets....534

Counters....540

defaultdict....543

Conditional Expressions....546

List Comprehensions....549

any and all....553

Named Tuples....555

Packing Keyword Arguments....559

Debugging....563

Glossary....567

Exercises....567

19. Final Thoughts....573

Index....577

About the Author....628

Python is an excellent way to get started in programming, and this clear, concise guide walks you through Python a step at a time—beginning with basic programming concepts before moving on to functions, data structures, and object-oriented design. This revised third edition reflects the growing role of large language models (LLMs) in programming and includes exercises on effective LLM prompts, testing code, and debugging skills.

With this popular hands-on guide at your side, you'll get:

  • A grounding in the syntax and semantics of the Python language
  • A clear definition of each programming concept, with emphasis on clear vocabulary
  • How to work with variables, statements, functions, and data structures in a logical progression
  • Techniques for reading and writing files and databases
  • A solid understanding of objects, methods, and object-oriented programming
  • Debugging strategies for syntax, runtime, and semantic errors
  • An introduction to recursion, interface design, data structures, and basic algorithms
  • How to use LLMs—including effective prompts, testing code, and debugging
  • And more

Похожее:

Список отзывов:

Нет отзывов к книге.