[Tutor] Built In Functions

eryksun eryksun at gmail.com
Wed Dec 18 12:37:05 CET 2013


On Tue, Dec 17, 2013 at 10:51 AM, Rafael Knuth <rafael.knuth at gmail.com> wrote:
> Got it. I just wanted to make sure I get a better understanding of how
> to use any() and all() even though I already had a solution at hand.
> So far, I worked through 24 out of 68 built-in functions

68 is the total for types (26) and functions (42). It omits the
undocumented built-in __build_class__, understandably, yet includes
help(), which is neither built-in nor always available (it's a wrapper
that proxies a pydoc.Helper).

http://docs.python.org/3/library/dis#opcode-LOAD_BUILD_CLASS

All together, builtins in CPython 3.3 contains 148 names on my Linux box:

    >>> import builtins
    >>> len(dir(builtins))
    148

It's 149 in Windows CPython, which aliases OSError to WindowsError for
compatibility with previous releases.

Here's the breakdown:

1 name that exists only in interactive mode, set to the last printed
result by sys.displayhook:

    _ (just an underscore)

4 attributes of the builtins module that are normally shadowed by the
current module:

    __name__    == "builtins"
    __doc__     == "Built-in functions, exceptions,
                    and other objects..."
    __package__ == None
    __loader__  == BuiltinImporter

42 built-in functions:

    open [*]     id           issubclass
    input        hash         isinstance
    compile      repr         callable
    exec         ascii        hasattr
    eval         len          getattr
    globals      vars         setattr
    locals       dir          delattr

    abs          any          bin
    pow          all          oct
    divmod       iter         hex
    round        next         format
    sum          sorted       print
    min          ord          __build_class__
    max          chr          __import__

    [*] _io.open

22 built-in types that can be subclassed:

    object       int          tuple
    type         float        list
    super        complex      set
    property     bytes        frozenset
    classmethod  bytearray    dict
    staticmethod str

    zip          map
    enumerate    filter
    reversed

4 built-in types that cannot be subclassed:

    bool
    slice
    range
    memoryview

5 singleton objects:

    None  [*]
    False [*]
    True  [*]
    NotImplemented
    Ellipsis (...)

    [*] keyword

1 boolean indicating the interpreter debug state:

    __debug__ (keyword)

    This affects the compiler. If you start the interpreter
    with the -O optimized code option, __debug__ is set to
    False and the compiler optimizes away assert statements
    and simple `if __debug__` statements.

6 callables from the site module (i.e. these won't exist if you start
the interpreter with the -S option):

    help
    exit
    quit
    credits
    copyright
    license

61 exceptions:

    BaseException
        GeneratorExit
        KeyboardInterrupt
        SystemExit
        Exception
            ArithmeticError
                FloatingPointError
                OverflowError
                ZeroDivisionError
            AssertionError
            AttributeError
            BufferError
            EOFError
            ImportError
            LookupError
                IndexError
                KeyError
            MemoryError
            NameError
                UnboundLocalError
            OSError
                BlockingIOError
                ChildProcessError
                ConnectionError
                    BrokenPipeError
                    ConnectionAbortedError
                    ConnectionRefusedError
                    ConnectionResetError
                FileExistsError
                FileNotFoundError
                InterruptedError
                IsADirectoryError
                NotADirectoryError
                PermissionError
                ProcessLookupError
                TimeoutError
            ReferenceError
            RuntimeError
                NotImplementedError
            StopIteration
            SyntaxError
                IndentationError
                    TabError
            SystemError
            TypeError
            ValueError
                UnicodeError
                    UnicodeDecodeError
                    UnicodeEncodeError
                    UnicodeTranslateError
            Warning
                BytesWarning
                DeprecationWarning
                FutureWarning
                ImportWarning
                PendingDeprecationWarning
                ResourceWarning
                RuntimeWarning
                SyntaxWarning
                UnicodeWarning
                UserWarning

2 or 3 aliases of OSError, for compatibility:

    EnvironmentError
    IOError
    WindowsError


More information about the Tutor mailing list