内容简介
Python的简洁让你可以快速达到高产水平,但是这通常意味着你并没有用到它提供的所有功能特性。
有了《流利的Python语言(影印版英文版)》,你将学会如何利用那些很容易被忽视的特性来编写有效且通顺的Python代码。作者LucianoRamalho将带领你们遍历Python的核心语言特性和程序库,并展示精简代码、优化速度和可读性的方法。
很多富有经验的程序员尝试将Python扭曲成适合他们从其他语言中学到的模式,而从未发现超出他们经验的Python特性。通过《流利的Python语言(影印版英文版)》,那些Python程序员将完全学会如何高效率地使用Python3。目录
Preface
PartI.Prologue
1.ThePythonDataModel
APythonicCardDeck
HowSpecialMethodsAreUsed
EmulatingNumericTypes
StringRepresentation
ArithmeticOperators
BooleanValueofaCustomType
OverviewofSpecialMethods
WhylenIsNotaMethod
ChapterSummary
FurtherReading
PartII.DataStructures
2.AnArrayofSequences
OverviewofBuilt-InSequences
ListComprehensionsandGeneratorExpressions
ListComprehensionsandReadability
ListcompsVersusmapandfilter
CartesianProducts
GeneratorExpressions
TuplesAreNotJustImmutableLists
TuplesasRecords
TupleUnpacking
NestedTupleUnpacking
NamedTuples
TuplesasImmutableLists
Slicing
WhySlicesandRangeExcludetheLastItem
SliceObjects
MultidimensionalSlicingandEllipsis
AssigningtoSlices
Using+and*withSequences
BuildingListsofLists
AugmentedAssignmentwithSequences
A+=AssignmentPuzzler
list.sortandthesortedBuilt-InFunction
ManagingOrderedSequenceswithbisect
Searchingwithbisect
Insertingwithbisect.insort
WhenaListIsNottheAnswer
Arrays
MemoryViews
NumPyandSciPy
DequesandOtherQueues
ChapterSummary
FurtherReading
3.DictionariesandSets
GenericMappingTypes
dictComprehensions
OverviewofCommonMappingMethods
HandlingMissingKeyswithsetdefault
MappingswithFlexibleKeyLookup
defaultdict:AnotherTakeonMissingKeys
The___missing___Method
Variationsofdict
SubclassingUserDict
ImmutableMappings
SetTheory
setLiterals
SetComprehensions
SetOperations
dictandsetUndertheHood
APerformanceExperiment
HashTablesinDictionaries
……
PartIII.FunctionsasObjects
PartIV.Object-Orientedldioms
PartV.ControlFlow
PartVI.Metaprogramming
Afterword
A.SupportScripts
PythonJargon
Index精彩书摘
《流利的Python语言(影印版英文版)》:
Inconcludingthechapter,wementionedhowseveralbuilt—intypesareregisteredtoABCsinthecollections.abemodulesoyoucanaskisinstance(memoryview,abc.Sequence)andgetTrue,evenifmemoryviewdoesnotinheritfromabc.Sequence.Andfinallywewentoverthe_subclasshook_magic,whichletsanABCrecognizeanyunregisteredclassasasubclass,aslongasitpassesatestthatcanbeassimpleorascomplexasyoulike—theexamplesinthestandardlibrarymerelycheckformethodnames.
Tosumup,I'dliketorestateAlexMartelli'sadmonitionthatweshouldrefrainfromcreatingourownABCs,exceptwhenwearebuildinguser—extensibleframeworks—whichmostofthetimewearenot.Onadailybasis,ourcontactwithABCsshouldbesubclassingorregisteringclasseswithexistingABCs.Lessoftenthansubclassingorregistering,wemightuseABCsforisinstancechecks.Andevenmorerarely—ifever—wefindoccasiontowriteanewABCfromscratch.
……