“Computer Programming for Everybody.”- Guido van R

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1CS280StructureofProgrammingLanguagesPython:NewBreedofLanguage?WiillammEmanuelS.YuMSCSDepartmentofInformationSystemsandComputerScienceAteneodeManilaUniversity2“ComputerProgrammingforEverybody.”-GuidovanRossum,InventorofPython3■Introduction■History■Relationships■FeaturesLanguageBeginner'sLanguage■Installation■Programming■ReferencesContents4Introduction■PythonProgrammingLanguage■Interpreted,interactive,extensible,object-orientedprogramminglanguage■LanguagecreatedandtargetedforBeginners■LicensesunderthePythonSourceLicense(PSL)BSD-typelicenseWithadvertisingclauseIsGPL-compatible■PortableUnixvariantsontheMac,andonPCsMS-DOS,MSWindows5History■WrittenintheChristmasof1989Wasprobablybored■PostedinUsenetonFeb1991■NamedaftertheBBCcomedy-MontyPython'sFlyingCircus■DevelopedbyGuidovanRossumWorkedforCentrumvoorWiskundeenInformatica(CWI)intheNetherlandsParticipatedinthedevelopmenttheABClanguageNeedsomethingbetter6Relationships■PythonisgeneralpurposeprogramminglanguageEaseandflexibilityofscriptinglanguagesandtoolsRigidityandcompletenessofsystemlanguages■Pythonisinthemiddle!7LanguageFeatures■ClearsyntaxUnlikeC,JavaandotherBNFlanguagesInflexiblesyntaxforcescodediscipline■SupportsmodulesBindingstoC/C++orcanbebindedwithC/C++EasytowritePythonmodulesforotherlanguages■ExceptionsReal-timetrappingoferrorsandcorrectingoferrors■Dynamictyping/Auto-boundsCheckingNoneedtospecifyexactdatatypes■VeryhighlevelanddynamicdatatypesTouples,lists,dictionaries,complexnumbersandothersaresupported■Object-oriented8Beginner'sLanguage■ElegantSyntaxforReadablePrograms■InterpretedLanguagesMakesiteasytotryoutsnippetsofcode■LargeSetofSystemLibrariesandComponentsDon'tneedtocodefromscratchjustloadlibrariesSystemCalls,RegularExpressions,Sockets■ProceduralandOOLanguageEasiertoteachbasicsinproceduralandgraduallyevolvetoobject-oriented■Dynamicvs.StaticDataTypesStatictypesareunnaturalforanewprogrammerBut,operatingonincompatibletypescausesexceptionsBut,isagoodthing(tm)inthelongterm■AutomaticGarbageCollection-Yipee!9Installation■ForLinux,PythonisinstalledbydefaultonallmajorLinuxdistributions.■IfPythonisnotinstalledbydefaultyoucaninstallitfromyourdistributionsCDmedia.■ForMSWindows,downloadthePythoninstallerfrom:■Dynamicallytyped■SimpleDataTypes:IntegersFloatingPointNumbersCharactersandStrings■SpecialDataTypes:ComplexNumbersListsDictionary12NumericDataTypesmyint=1myfloat=1.00000000001mycomplex=1+1jprintthisisaninteger:,myint+2printthisisanfloatingpointnumber:,myfloat+0.1111111printthisisancomplexnumber:,mycomplex+1j13Stringsmystring=“Test”printthisisastring:+mystringprintthisisastring(repeated5times):+mystring*5printthisisastring(first2chars):+mystring[:2]printthisisastring(last2chars):+mystring[-2:]14Listsmylist=['a','b','c']mylist2=['d','e','f']printthisisalist:,mylistprintthisisalist(concated):,mylist+mylist2printthisisalist(concatedonlyfirstandlast):,printmylist[:1]+mylist2[-1:]printthisisalist(listwithinalist):,mylist[0]=mylist2printmylist15Dictionary■Alsoreferredtoasassociativearrays■SimilartoPerlhashestel={'jack':4098,'sape':4139,'helpdesk':7007}printtel['helpdesk']16LambdaFunctions■Takenfromfunctionalprogramminglanguages■Addstheabilitytocreateanonymousfunctions■SampleCodex=10inc=lambdax:x+1printinc(x)17ListsasStacksStack=[1,2,3,4,5]stack.append(6)stack.append(7)printstackprintstack.pop()printstackprintstack.pop()printstackprintstack.pop()printstack18ListsasQueuesqueue=[1,2,3,4,5]queue.append(6)queue.append(7)printqueueprintqueue.pop(0)printqueueprintqueue.pop(0)printqueueprintqueue.pop(0)printqueue19SpecialFunctions■Filterdeff(x):returnx%2!=0andx%3!=0printfilter(f,range(1,10))■Mapdefcube(x):returnx*x*xprintmap(cube,range(1,4))■Reducedefadd(x,y):returnx+yprintreduce(add,range(1,5))seq=range(1,5)printmap(add,seq,seq)20MoreDemonstration(iftimepermits)21References■PythonWebsite■PythonTutorial■PythonLibraryReference■PythonReferenceManual

1 / 21
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功