Learning Python: Powerful Object-Oriented Programming ppt

1,213 5,469 1
  • Loading ...
    Loading ...
    Loading ...

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Tài liệu liên quan

Thông tin tài liệu

Ngày đăng: 07/03/2014, 04:20

www.it-ebooks.infoLearning Pythonwww.it-ebooks.infowww.it-ebooks.infoFOURTH EDITIONLearning PythonMark LutzBeijing•Cambridge•Farnham•Köln•Sebastopol•Taipei•Tokyowww.it-ebooks.infoLearning Python, Fourth Editionby Mark LutzCopyright © 2009 Mark Lutz. All rights reserved.Printed in the United States of America.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 editionsare also available for most titles (http://my.safaribooksonline.com). For more information, contact ourcorporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.Editor: Julie SteeleProduction Editor: Sumita MukherjiCopyeditor: Rachel HeadProduction Services: Newgen North AmericaIndexer: John BickelhauptCover Designer: Karen MontgomeryInterior Designer: David FutatoIllustrator: Robert RomanoPrinting 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 ofO’Reilly Media, Inc. Learning Python, the image of a wood rat, and related trade dress are trademarksof O’Reilly Media, Inc.Many of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of atrademark 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 assumeno 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]1252944666www.it-ebooks.infoTo Vera.You are my life.www.it-ebooks.infowww.it-ebooks.infoTable of ContentsPreface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiPart I. Getting Started 1. A Python Q&A Session . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Why Do People Use Python? 3Software Quality 4Developer Productivity 5Is Python a “Scripting Language”? 5OK, but What’s the Downside? 7Who Uses Python Today? 7What Can I Do with Python? 9Systems Programming 9GUIs 9Internet Scripting 10Component Integration 10Database Programming 11Rapid Prototyping 11Numeric and Scientific Programming 11Gaming, Images, Serial Ports, XML, Robots, and More 12How Is Python Supported? 12What Are Python’s Technical Strengths? 13It’s Object-Oriented 13It’s Free 13It’s Portable 14It’s Powerful 15It’s Mixable 16It’s Easy to Use 16It’s Easy to Learn 17It’s Named After Monty Python 17How Does Python Stack Up to Language X? 17viiwww.it-ebooks.infoChapter Summary 18Test Your Knowledge: Quiz 19Test Your Knowledge: Answers 192. How Python Runs Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Introducing the Python Interpreter 23Program Execution 24The Programmer’s View 24Python’s View 26Execution Model Variations 29Python Implementation Alternatives 29Execution Optimization Tools 30Frozen Binaries 32Other Execution Options 33Future Possibilities? 33Chapter Summary 34Test Your Knowledge: Quiz 34Test Your Knowledge: Answers 343. How You Run Programs . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35The Interactive Prompt 35Running Code Interactively 37Why the Interactive Prompt? 38Using the Interactive Prompt 39System Command Lines and Files 41A First Script 42Running Files with Command Lines 43Using Command Lines and Files 44Unix Executable Scripts (#!) 46Clicking File Icons 47Clicking Icons on Windows 47The input Trick 49Other Icon-Click Limitations 50Module Imports and Reloads 51The Grander Module Story: Attributes 53import and reload Usage Notes 56Using exec to Run Module Files 57The IDLE User Interface 58IDLE Basics 58Using IDLE 60Advanced IDLE Tools 62Other IDEs 63Other Launch Options 64viii | Table of Contentswww.it-ebooks.infoEmbedding Calls 64Frozen Binary Executables 65Text Editor Launch Options 65Still Other Launch Options 66Future Possibilities? 66Which Option Should I Use? 66Chapter Summary 68Test Your Knowledge: Quiz 68Test Your Knowledge: Answers 69Test Your Knowledge: Part I Exercises 70Part II. Types and Operations 4. Introducing Python Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Why Use Built-in Types? 76Python’s Core Data Types 77Numbers 78Strings 80Sequence Operations 80Immutability 82Type-Specific Methods 82Getting Help 84Other Ways to Code Strings 85Pattern Matching 85Lists 86Sequence Operations 86Type-Specific Operations 87Bounds Checking 87Nesting 88Comprehensions 88Dictionaries 90Mapping Operations 90Nesting Revisited 91Sorting Keys: for Loops 93Iteration and Optimization 94Missing Keys: if Tests 95Tuples 96Why Tuples? 97Files 97Other File-Like Tools 99Other Core Types 99How to Break Your Code’s Flexibility 100Table of Contents | ixwww.it-ebooks.info[...]... Contents | xxix www.it-ebooks.info www.it-ebooks.info Preface This book provides an introduction to the Python programming language Python is a popular open source programming language used for both standalone programs and scripting applications in a wide variety of domains It is free, portable, powerful, and remarkably easy and fun to use Programmers from every corner of the software industry have found... rather than specific applications of it As such, it’s intended to serve as the first in a two-volume set: • Learning Python, this book, teaches Python itself • Programming Python, among others, shows what you can do with Python after you’ve learned it That is, applications-focused books such as Programming Python pick up where this book leaves off, exploring Python’s role in common domains such as the... edition for 3.0 and 2.6, I’ve also added five new chapters to address new topics and add context: • Chapter 27 is a new class tutorial, using a more realistic example to explore the basics of Python object-oriented programming (OOP) • Chapter 36 provides details on Unicode and byte strings and outlines string and file differences between 3.0 and 2.6 • Chapter 37 collects managed attribute tools such as properties... Function Annotations in 3.0 Anonymous Functions: lambda lambda Basics Why Use lambda? How (Not) to Obfuscate Your Python Code Nested lambdas and Scopes Mapping Functions over Sequences: map Functional Programming Tools: filter and reduce Chapter Summary Test Your Knowledge: Quiz Test Your Knowledge: Answers 463 465 465 466 467 468 469 469 470 471 472 474 474 475 477 478 479 481 483 483 483 20 Iterations... included here, and it is designed to supplement this book Because of this book’s foundations focus, though, it is able to present Python fundamentals with more depth than many programmers see when first learning the language And because it’s based upon a three-day Python training class with quizzes and exercises throughout, this book serves as a self-paced introduction to the language xxxi www.it-ebooks.info... also freely introduce new features, such as the nonlocal statement in 3.0 and the string format method in 2.6 and 3.0, and will point out when such extensions are not present in older Pythons If you are learning Python for the first time and don’t need to use any legacy code, I encourage you to begin with Python 3.0; it cleans up some longstanding warts in the language, while retaining all the original... from every corner of the software industry have found Python’s focus on developer productivity and software quality to be a strategic advantage in projects both large and small Whether you are new to programming or are a professional developer, this book’s goal is to bring you quickly up to speed on the fundamentals of the core Python language After reading this book, you will know enough about Python . 9Systems Programming 9GUIs 9Internet Scripting 10Component Integration 10Database Programming 11Rapid Prototyping 11Numeric and Scientific Programming. www.it-ebooks.info Learning Pythonwww.it-ebooks.infowww.it-ebooks.infoFOURTH EDITION Learning PythonMark LutzBeijing•Cambridge•Farnham•Köln•Sebastopol•Taipei•Tokyowww.it-ebooks.infoLearning
- Xem thêm -

Xem thêm: Learning Python: Powerful Object-Oriented Programming ppt, Learning Python: Powerful Object-Oriented Programming ppt, Learning Python: Powerful Object-Oriented Programming ppt, Chapter 1. A Python Q&A Session, Chapter 2. How Python Runs Programs, Chapter 3. How You Run Programs, Chapter 4. Introducing Python Object Types, Chapter 6. The Dynamic Typing Interlude, Chapter 9. Tuples, Files, and Everything Else, Chapter 11. Assignments, Expressions, and Prints, Chapter 12. if Tests and Syntax Rules, Avoid mixing tabs and spaces: New error checking in 3.0, Chapter 13. while and for Loops, Chapter 14. Iterations and Comprehensions, Part 1, Chapter 20. Iterations and Comprehensions, Part 2, Chapter 21. Modules: The Big Picture, Chapter 25. OOP: The Big Picture, Chapter 27. A More Realistic Example, Chapter 36. Unicode and Byte Strings, Caveat: operator overloading methods fail to delegate under 3.0, Appendix B. Solutions to End-of-Part Exercises

Mục lục

Xem thêm