Abstract
A reference guide to most of the common features of the Python programming language, version 2.7.
This publication is available in Web form and also as a
PDF document. Please forward any comments to tcc-doc@nmt.edu.
Table of Contents
str: Strings of 8-bit
charactersunicode: Strings of 32-bit
characterslist: Mutable sequencestuple: Immutable sequencesbytes typebytearray typeset and frozenset:
Set typesdict: Dictionariesfile: Input and output filesNone: The special placeholder valueabs(): Absolute valueall(): Are all the elements of an
iterable true?any(): Are any of the members of an
iterable true?bin(): Convert to binarybool(): Convert to Booleanbytearray(): Create a byte arraychr(): Get the character with a given
codecmp(): Compare two valuescomplex(): Convert to complex typedict(): Convert to a dictionarydivmod(): Quotient and remainderenumerate(): Step through indices and
values of an iterablefile(): Open a filefilter(): Extract qualifying elements
from an iterablefloat(): Convert to float typeformat(): Format a valuefrozenset(): Create a frozen sethex(): Convert to base 16int(): Convert to int typeinput(): Read an expression from the
useriter(): Produce an iterator over a
sequencelen(): Number of elementslist(): Convert to a listlong(): Convert to long typemap(): Apply a function to each
element of an iterablemax(): Largest element of an
iterablemin(): Smallest element of an
iterablenext(): Call an iteratoroct(): Convert to base 8open(): Open a fileord(): Find the numeric code for a
characterpow(): Exponentiationrange(): Generate an arithmetic
progression as a listraw_input(): Prompt and read a string
from the userreduce(): Sequence reductionreversed(): Produce a reverse
iteratorround(): Round to the nearest
integral valueset(): Create an algebraic setsorted(): Sort a sequencestr(): Convert to str
typesum(): Total the elements of a
sequencetuple(): Convert to a tupletype(): Return a value's typeunichr(): Convert a numeric code to a
Unicode characterunicode(): Convert to a Unicode
stringxrange(): Arithmetic progression
generatorzip(): Combine multiple
sequencesbasestring: The string base classcallable(): Is this thing
callable?classmethod(): Create a class
methoddelattr(): Delete a named
attributedir(): Display a namespace's nameseval(): Evaluate an expression in source
formexecfile(): Execute a Python source
filegetattr(): Retrieve an attribute of a
given nameglobals(): Dictionary of global name
bindingshasattr(): Does a value have an attribute
of a given name?id(): Unique identifierisinstance(): Is a value an instance of
some class or type?issubclass(): Is a class a subclass of
some other class?locals(): Dictionary of local name
bindingsproperty(): Create an access-controlled
attributereload(): Reload a modulerepr(): Representationsetattr(): Set an attributeslice(): Create a slice instancestaticmethod(): Create a static
methodsuper(): Superclassvars(): Local variablesname = expressionassert statement: Verify
preconditionsdel statement: Delete a name or part
of a valueexec statement: Execute Python source
codeglobal statement: Declare access to a
global nameimport statement: Use a
modulepass statement: Do nothingprint statement: Display output
valuesprint() functionbreak statement: Exit a for or while loopcontinue statement: Jump to the next
cycle of a for or whilefor statement: Iteration over a
sequenceif statement: Conditional
executionraise statement: Cause an
exceptionreturn statement: Exit a function or
methodtry statement: Anticipate
exceptionswith statement and context
managersyield statement: Generate one result
from a generatordef(): Defining your own functions__call__(): What to do when someone
calls an instance__cmp__(): Generalized
comparison__contains__(): The “in” and “not in” operators__del__(): Destructor__delattr__(): Delete an
attribute__delitem__(): Delete one item of a
sequence__enter__: Context manager
initialization__exit__: Context manager
cleanup__format__: Implement the format() function__getattr__(): Handle a reference
to an unknown attribute__getattribute__(): Intercept all
attribute references__getitem__(): Get one item from a
sequence or mapping__iter__(): Create an iterator__nonzero__(): True/false
evaluation__repr__(): String representation__reversed__(): Implement the reversed() function__setattr__(): Intercept all
attribute changes__setitem__(): Assign a value to
one item of a sequencepdb: The Python interactive debuggermath: Common mathematical
operationsstring: Utility functions for stringsrandom: Random number generationtime: Clock and calendar functionsre: Regular expression
pattern-matchingsys: Universal system interfaceos: The operating
system interfacestat: Interpretation of file
statusos.path: File and directory interfaceargparse: Processing command line
arguments