IntroductionBook ConventionsPython Command-Line UsagePython Command OptionsCommand-Line Program SpecificationPython 2.X Command OptionsPython Environment VariablesOperational VariablesPython Command Option VariablesPython Windows Launcher UsageLauncher File DirectivesLauncher Command LinesLauncher Environment VariablesBuilt-in Types and OperatorsOperators and PrecedenceAtomic terms and dynamic typingOperator Usage NotesOperations by CategorySequence Operation NotesSpecific Built-in TypesNumbersLiterals and creationOperationsDecimal and fractionOther numeric typesStringsLiterals and creationOperationsString formattingString formatting expressionFormatting expression syntaxString formatting methodFormatting method syntaxTemplate string substitutionString methodsbyte and bytearray methodsSearching methodsSplitting and joining methodsFormatting methodsContent test methodsThe original string moduleUnicode StringsUnicode support in Python 3.Xbyte and bytearray stringsUnicode support in Python 2.XListsLiterals and creationOperationsList comprehension expressionsThe iteration protocolGenerator expressionsOther comprehension expressionsDictionariesLiterals and creationOperationsTuplesLiterals and creationOperationsFilesInput filesOutput filesAny filesOther file attributes (some read-only)File context managersFile usage notesSetsLiterals and creationOperationsOther Types and ConversionsBooleanType ConversionsStatements and SyntaxSyntax RulesName RulesName formatName conventionsSpecific StatementsThe Assignment StatementAugmented assignmentNormal sequence assignmentExtended sequence assignment (3.X)The Expression StatementCall syntaxArbitrary arguments call syntaxThe print StatementPython 2.X print statementsThe if StatementThe while StatementThe for StatementThe pass StatementThe break StatementThe continue StatementThe del StatementThe def StatementPython 3.X keyword-only argumentsPython 3.X function annotationslambda expressionsFunction defaults and attributesFunction and method decoratorsThe return StatementThe yield StatementGenerator function changes in Python 3.3The global StatementThe nonlocal StatementThe import StatementPackage importsPython 3.3 namespace packagesImport algorithmThe from StatementPackage relative import syntaxThe class StatementClass decorators in Python 3.X, 2.6, and 2.7MetaclassesThe try StatementPython 2.X try statement formsThe raise StatementPython 3.X chained exceptionsClass exceptionsPython 2.X raise statement formsThe assert StatementThe with StatementMultiple context managers in Python 3.1 and 2.7Context manager protocolPython 2.X StatementsNamespace and Scope RulesQualified Names: Object NamespacesUnqualified Names: Lexical ScopesNested Scopes and ClosuresEnclosing scopes and defaultsObject-Oriented ProgrammingClasses and InstancesClass objects provide default behaviorInstance objects are generated from classesInheritance rulesPseudoprivate AttributesModule privatesClass privatesNew-Style ClassesFormal Inheritance RulesClassic classes: DFLRNew-style classes: MROExample: nondiamondsExample: diamondsNew-style inheritance algorithmNew-style precedence and contextOperator Overloading MethodsMethods for All TypesMethods for Collections (Sequences, Mappings)Methods for Numbers (Binary Operators)Basic binary methodsRight-side binary methodsAugmented binary methodsMethods for Numbers (Other Operations)Methods for DescriptorsMethods for Context ManagersPython 2.X Operator Overloading MethodsMethods in Python 3.X onlyMethods in Python 2.X onlyBuilt-in FunctionsPython 2.X Built-in FunctionsPython 3.X built-ins not supported by Python 2.XPython 2.X built-ins not supported by Python 3.XBuilt-in ExceptionsSuperclasses: CategoriesSpecific ExceptionsSpecific OSError ExceptionsWarning Category ExceptionsWarnings FrameworkPython 3.2 Built-in ExceptionsPython 2.X Built-in ExceptionsBuilt-in AttributesStandard Library ModulesThe sys ModuleThe string ModuleFunctions and ClassesConstantsThe os System ModuleAdministrative ToolsPortability ConstantsShell CommandsEnvironment ToolsFile Descriptor ToolsFile Pathname ToolsProcess ControlThe os.path ModuleThe re Pattern-Matching ModuleModule FunctionsRegular Expression ObjectsMatch ObjectsPattern SyntaxObject Persistence ModulesThe shelve and dbm ModulesFile opensFile operationsThe pickle ModulePickling interfacesUnpickling interfacespickle usage notesThe tkinter GUI Module and Toolstkinter Exampletkinter Core WidgetsCommon Dialog CallsModule tkinter.messagebox (tkMessageBox in Python 2.X)Module tkinter.simpledialog (tkSimpleDialog in Python
2.X)Module tkinter.colorchooser (tkColorChooser in Python
2.X)Module tkinter.filedialog (tkFileDialog in Python 2.X)Additional tkinter Classes and ToolsTcl/Tk-to-Python/tkinter MappingsInternet Modules and ToolsOther Standard Library ModulesThe math ModuleThe time ModuleThe timeit ModuleThe datetime ModuleThe random ModuleThe json ModuleThe subprocess ModuleThe enum ModuleThe struct ModuleThreading ModulesPython SQL Database APIAPI Usage ExampleModule InterfaceConnection ObjectsCursor ObjectsType Objects and ConstructorsMore Hints and IdiomsCore Language HintsEnvironment HintsUsage HintsAssorted Hints