学习PYTHON 第三版(英文影印版)
2008-8-1
东南大学出版社
(美国)(Lutz.M.)卢茨
700
无
About This Third Edition . In the four years since the second edition of this book was published in late 2003, there have been substantial changes in Python itself, and in the topics I present in Python training sessions. Although I have attempted to retain as much of the prior version of this text as possible, this new edition reflects many recent changes in the Python language and in Python training, as well as a handful of structural changes. This Edition’s Python Language Changes On the language front, this edition has been thoroughly updated to reflect Python 2.5 and all changes to the language since the publication of the second edition. (The second edition was based largely on Python 2.2, with some 2.3 features grafted on at the end of the project.) In addition, discussions of anticipated changes in the upcoming Python 3.0 release have been incorporated where appropriate. Here are some of the major language topics of which you’ll find new or expanded coverage in this edition: The new B if A else C conditional expression (Chapter 12). with/as context managers (Chapter 27). try/except/finally unification (Chapter 27). Relative import syntax (Chapter 21). .. Generator expressions (Chapter 17). New generator function features (Chapter 17). Function decorators (Chapter 26). The set object type (Chapter 5). New built-in functions: sorted, sum, any, all, enumerate (Chapters 4 and 13). The decimal fixed-precision object type (Chapter 5). New and expanded material on files, list comprehensions, iterators, and more (Chapters 13 and 17). New development tools coverage: Eclipse, distutils, unittest and doctest, IDLE enhancements, Shedskin, and so on (Chapters 3 and 29). Smaller language changes (for instance, the widespread use of True and False, the new sys.exc_info for fetching exception details, and the demise of string-based exceptions, string methods, and the apply and reduce built-ins) are discussed throughout the book. In addition, some of the features that were new in the prior edition enjoy substantially expanded coverage here, including three-limit slices, and the arbitrary arguments call syntax that subsumes apply.
Python是一种理想的独立程序和脚本程序语言,具有可移植、强大和易用的特点。无论您是初学程序设计还是初学Python,都能通过本书快速而高效地掌握Python核心语言的基础。通读本书,您可以获得足够多的知识,能够学习将Python用于您所选择的任何应用领域。 《学习Python(第三版)》基于作者Mark Lutz在过去10年间讲授培训课程所使用的资料。除了大量的注解插图和每章总结外,作者还为每章加入了独特的一节,通过实际练习和复习提问的方式,让您在学习过程中练习新的技能,测验对概念的理解程度。 本书内容包括: 类型和运算——深入Python内置对象类型:数值、列表、字典及其他。 语句和语法——用来创建和处理对象的Python代码以及Python通用语法模型。 函数——Python的基本结构化和代码重用工具。 模块——将语句、函数和其他工具组织为更大的组件。 类和面向对象编程——可选的Python面向对象程序设计工具,用于定制和重用结构化代码。 异常和工具——处理语句和模块异常,并介绍编写较大型程序所使用的开发工具。 有关即将发布的Python 3.0的一些讨论。 《学习Python 第三版》为您理解Python语言提供了完整而又深入的介绍,帮助您领会在以后的工作中会遇到的应用级Python实例。如果您准备好探索Google和YouTube究竟从Python中发现了什么,那么本书就是一个最好的开始。
卢茨 (Lutz.M.),作为Python培训界的领军人物,Mark Lutz是有关Python方面的最早和最畅销书籍的作者,并且从1992年起就是Python社区的先驱之一。同时他还是OReilly的《Programming Python》和《Python Pocket Reference》两本书的作者。Mark从1997年开始教授Python课程,截至2007年已经指导了超过200次培训。此外Mark拥有计算机科学学士和硕士学位,以及25年的软件开发经验。
PrefacePartⅠ.Getting Started1.A Python Q&A SessionWhy Do People Use Python?Software Quality Developer ProductivityIs Python a“Scripting Language”?OK,but What’S the Downside?Who Uses Python Today?What Can I Do with Python?Systems ProgrammingGUIsInternet ScriptingComponent IntegrationDatabase ProgrammingRapid PrototypingNumeric and Scientific ProgrammingGaming,Images,AI,XML,Robots,and MoreWhat Are Python’S Technical Strengths?It’S Object OrientedIt’S FreeIt’S PortableIt’S PowerfulIt’S Mixable It’S Easy to UseIt’S Easy to LearnIt’s Named After Monty PythonHow Does Python Stack Up to Language X?Chapter SummaryBrain BuilderChapter QuizQuiz Answers2.How Python Runs ProgramsIntroducing the Python InterpreterProgram ExecutionThe Programmer’S ViewPython’S ViewByte code compilationThe Python Virtual Machine(PVM)Performance implicationsDevelopment implicationsExecution Model VariationsPython Implementation Alternatives CPythonJythonIronPythonExecution Optimization ToolsThe Psyco just-in-time compilerThe Shedskin C++translatorFrozen BinariesFuture Possibilities?Chapter SummaryBrain BuilderChapter QuizQuiz Answers3.How You Run ProgramsInteractive CodingUsing the Interactive PromptSystem Command Lines and FilesUsing Command Lines and FilesUnix Executable Scripts(#!)Clicking File IconsClicking Icons on WindowsThe raw_input Trick0ther Icon-Click LimitationsModule Imports and ReloadsThe Grander Module Story:AttributesModules and namespacesimport and reload Usage NotesThe IDLE User InterfaceIDLE BasicsUsing 1DLEAdvanced 1DLE Tools0ther IDEsEmbedding CallsFrozen Binary ExecutablesText Editor Launch Options0ther Launch OptionsFuture Possibilities?Which 0ption Should I Use?Chapter SummaryBrain BuilderChapter QuizOuiz AnswersBrain Builder:Part I ExercisesPartⅡ.Types and Operations4.Introducing Python 0bject TypesWhy Use Built—in Types?Python’S Core Data TypesNumbersStringsSequence OperationsImmutabilityType—Specific MethodsGetting HelpOther Ways to Code StringsPattern MatchingListsSequence OperationsType—Specific OperationsBounds CheckingNestingList ComprehensionsDictionariesMapping OperationsNesting RevisitedSorting Keys:for LoopsIteration and OptimizationMissing Keys:if TestsTuples Why Tuples?FilesOther File-Like ToolsOther Core TypesHow to Break Your Code’S Flexibility User—Defined ClassesAnd Everything ElseChapter SummaryBrain BuilderChapter QuizQuiz Answers5.Numbers Python Numeric TypesNumeric LiteralsBuilt—in Numeric Tools and ExtensionsPython Expression OperatorsMixed Operators Follow Operator PrecedenceParentheses Group SubexpressionsMixed Types Are Converted UpPreview:Operator OverloadingNumbers in ActionVariables and Basic ExpressionSNumeric Display FormatsDivision:Classic,Floor,and TrueBitwise OperationsLong IntegersComplex NumbersHexadecimal and Octal NotationOther Built.in Numeric ToolsOther Numeric TypesDecimal NumbersSetsBooleansThird.Party ExtensionsChapter SummaryBrain BuilderChapter QuizQuiz Answers6.The DynamicTyping InterludeThe Case of the Missing Declaration StatementsVariables,Objects,and ReferencesTypes Live with Objects,Not VariablesObjects Are Garbage—CollectedShared Refe:rencesShared References and In—Place ChangesShared References and EqualityDynamic Typing Is EverywhereChapter SummaryBrain BuilderChapter QuizQuiz Answers7.StringsString LiteralsSingle,and Double.Quoted Strings Are the SameEscape Sequences Represent Special BytesRaw Strings Suppress EscapesTriple Quotes Code Multiline Block StringsUnicode Strings Encode Larger Character SetsStrings in ActionBasic OperationsIndexing and Slicing Extended slicing:the third limitString Conversion ToolsCharacter code conversionsChanging StringsString FormattingAdvanced String FormattingDictionary—Based String FormattingString MethodsString Method Examples:Changing StringsString Method Examples:Parsing TextOther Common String Methods in ActionThe Original string ModuleGeneral Type CategoriesTypes Share Operation Sets by CategoriesMutable Types Can Be Changed In—PlaceChapter SummaryBrain BuilderChapter Quizquiz Answers8.Lists and DictionariesListsLists in ActionBasic List OperationsIndexing,Slicing,and MatrixesChanging Lists In—Place Index and slice assignmentsList method callsOther common list operationsDictionariesDictionaries in ActionBasic Dictionary OperationsChanging Dictionaries In—PlaceMore Dictionary MethodsA Languages TableDictionary Usage NotesUsing dictionaries to simulate flexible listsUsing dictionaries for sparse data structuresAvoiding missing-key errorsUsing dictionaries as“records”Other ways to make dictionariesChapter SummaryBrain BuilderChapter QuizQuiz Answers9.Tuples,Files,and Everthing ElseTuplesTuples in ActionTuple syntax peculiarities:commas and parenthesesConversions and immutabilityWhy Lists and Tuples?FilesOpening FilesUsing FilesFiles in ActionStoring and parsing Python objects in filesStoring native Python objects with pickleStoring and parsing packed binary data in filesOther File ToolsType Categories RevisitedObject FlexibilityReferences Versus CopiesComparisons,Equality,and TruthThe Meaning of True and False in PythonPython’S Type HierarchiesOther Types in PythonBuilt.in Type GotchasAssignment Creates References,Not CopiesRepetition Adds One Level Deep Beware of Cyclic Data StructuresImmutable Types Can’t Be Changed In-PlaceChapter SummaryBrain BuilderChapter QuizQuiz AnswersBrain Builder:Part II ExercisesPartⅢ Statements and SyntaxIntroducing Python StatementsPython Program Structure RevisitedPython’S StatementsATale ofTwo ifsWhat Python AddsWhat Python RemovesParentheses are optionalEnd of line iS end of statementEnd of indentation iS end of blockWhy Indentation Syntax?A Few Special CasesStatement rule special casesBlock rule special caseA Quick Example:Interactive LoopsA Simple Interactive LoopDoing Math on User InputsHandling Errors by Testing InputsHandling Errors with try StatementsNesting Code Three Levels DeepChapter SummaryBrain BuilderChapter QuizQuiz Answers11.Assignment,Expressions,and printAssignment StatementsAssignment Statement FormsSequence AssignmentsAdvanced sequence assignment patternsMultiple—Target AssignmentsMultiple—target assignment and shared referencesAugmented AssignmentsAugmented assignment and shared referencesVariable Name RulesNaming conventionsNames have no type,but objects doExpression StatementsExpression Statements and In-Place Changesprint StatementsThe Python“Hello World”ProgramRedirecting the Output StreamThe print〉〉file ExtensionChapter SummaryBrain BuilderChapter QuizQuiz Answers12.if Tesisif Statements General FormatBasic ExamplesMultiway BranchingPython Syntax RulesBlock DelimitersStatement DelimitersA Few Special CasesTruth TestsThe if/else Ternary ExpressionChapter SummaryBrain BuilderChapter QuizQuiz Answers13.while and for Loopswhile LoopsGeneral FormatExamplesbreak,continue,pass,and the Loop elseGeneral Loop FormatExamplespasscontinuebreakelseMore on the loop else clauseforLoopsGeneral FormatExamplesBasic usageOther data typesTuple assignment in forNested for loopsIterators:A First LookFile IteratorsOther Built—in Type IteratorsOther Iteration ContextsUser—Defined IteratorsLoop Coding TechniquesCounter Loops:while and rangeNonexhaustive Traversals:rangeChanging Lists:rangeParallel Traversals:zip and mapDictionary construction with zipGenerating Both 0ffsets and Items:enumerateList Comprehensions:A First LookList Comprehension BasicsUsing List Comprehensions on FilesExtended List Comprehension SyntaxChapter SummaryBrain BuilderChapter QuizQuiz Answers14.The Documentation InterludePython Documentation Sources#CommentsThe dir FunctionDocstrings:--doc--User-defined docstringsDocstring standardsBuilt-in docstringsPyDoc:The help FunctionPyDoc:HTML ReportsStandard Manual SetWeb ResourcesPublished BooksCommon Coding Gotchas……PartⅣ Function15.Function Basics16.Scopes and Arguments17.Advanced Function TopicsPartⅤ.Modules18.Modules:The Big Picture19.Module Coding Basics20.Module Packages21.Advanced Module TopicsPartⅥ Classes and OOP22.OOP:The Big Picture23.Class Coding Basics24.Class Coding Details25.Designing with Classes26.Advanced Class TopicsPartⅦ Exceptions and Tools27.Exception Basics28.Exception Objects29.Designing with ExceptionsPartⅧ AppendixesA.Installation and ConfigurationB.Solutions to End-of-Part ExercisesIndex
卢茨(Lutz,M),作为Python培训界的领军人物,Mark Lutz是有关Python方面的最早和最畅销书籍的作者,并且从1992年起就是Python社区的先驱之一。同时他还是OReilly的《Programming Python》和《Python Pocket Reference》两本书的作者。Mark从1997年开始教授Python课程,截至2007年已经指导了超过200次培训。此外Mark拥有计算机科学学士和硕士学位,以及25年的软件开发经验。
无