ref.pdf

(453 KB) Pobierz
Python Reference Manual
PythonReferenceManual
Release2.5
GuidovanRossum
FredL.Drake,Jr.,editor
19thSeptember,2006
PythonSoftwareFoundation
Email: docs@python.org
Copyrightc 2001-2006PythonSoftwareFoundation.Allrightsreserved.
Copyright c 2000BeOpen.com.Allrightsreserved.
Copyrightc 1995-2000CorporationforNationalResearchInitiatives.Allrightsreserved.
Copyright c 1991-1995StichtingMathematischCentrum.Allrightsreserved.
Seetheendofthisdocumentforcompletelicenseandpermissionsinformation.
Abstract
Pythonisaninterpreted,object-oriented,high-levelprogramminglanguagewithdynamicsemantics.Itshigh-
levelbuiltindatastructures,combinedwithdynamictypinganddynamicbinding,makeitveryattractivefor
rapidapplicationdevelopment,aswellasforuseasascriptingorgluelanguagetoconnectexistingcomponents
together.Python’ssimple,easytolearnsyntaxemphasizesreadabilityandthereforereducesthecostofprogram
maintenance.Pythonsupportsmodulesandpackages,whichencouragesprogrammodularityandcodereuse.The
Pythoninterpreterandtheextensivestandardlibraryareavailableinsourceorbinaryformwithoutchargeforall
majorplatforms,andcanbefreelydistributed.
Thisreferencemanualdescribesthesyntaxand“coresemantics”ofthelanguage.Itisterse,butattemptsto
beexactandcomplete.Thesemanticsofnon-essentialbuilt-inobjecttypesandofthebuilt-infunctionsand
modulesaredescribedinthe PythonLibraryReference . Foraninformalintroductiontothelanguage,seethe
PythonTutorial . ForCorC ++ programmers,twoadditionalmanualsexist: ExtendingandEmbeddingthePython
Interpreter describesthehigh-levelpictureofhowtowriteaPythonextensionmodule,andthe Python/CAPI
ReferenceManual describestheinterfacesavailabletoC/C ++ programmersindetail.
CONTENTS
1Introduction 1
1.1AlternateImplementations ...................................... 1
1.2Notation ............................................... 2
2Lexicalanalysis 3
2.1Linestructure ............................................. 3
2.2Othertokens ............................................. 6
2.3 Identifiersandkeywords ....................................... 6
2.4Literals ................................................ 7
2.5Operators ............................................... 10
2.6Delimiters .............................................. 10
3Datamodel 13
3.1Objects,valuesandtypes ....................................... 13
3.2Thestandardtypehierarchy ..................................... 14
3.3New-styleandclassicclasses .................................... 20
3.4Specialmethodnames ........................................ 21
4Executionmodel 33
4.1Namingandbinding ......................................... 33
4.2Exceptions .............................................. 34
5Expressions 37
5.1Arithmeticconversions ........................................ 37
5.2Atoms ................................................ 37
5.3Primaries ............................................... 40
5.4Thepoweroperator .......................................... 42
5.5Unaryarithmeticoperations ..................................... 43
5.6Binaryarithmeticoperations ..................................... 43
5.7Shiftingoperations .......................................... 44
5.8Binarybit-wiseoperations ...................................... 44
5.9Comparisons ............................................. 44
5.10Booleanoperations .......................................... 46
5.11Lambdas ............................................... 46
5.12Expressionlists ............................................ 46
5.13Evaluationorder ........................................... 47
5.14Summary ............................................... 47
6Simplestatements 49
6.1Expressionstatements ........................................ 49
6.2Assertstatements .......................................... 49
6.3Assignmentstatements ....................................... 50
6.4The pass statement ......................................... 52
6.5The del statement ......................................... 52
i
Zgłoś jeśli naruszono regulamin