How to get the list of all built in functions in Python How to get the list of all built in functions in Python python-3.x python-3.x

How to get the list of all built in functions in Python


UPDATE:

There can be some confusion about __builtins__ or __builtin__.The What’s New In Python 3.0 suggests to use builtins

Renamed module __builtin__ to builtins (removing the underscores, adding an ‘s’). The __builtins__ variable found in most global namespaces is unchanged. To modify a builtin, you should use builtins, not __builtins__!

This may be good if you work with a different Python implementation as the docs indicate:

As an implementation detail, most modules have the name __builtins__ made available as part of their globals. The value of __builtins__ is normally either this module or the value of this module’s __dict__ attribute. Since this is an implementation detail, it may not be used by alternate implementations of Python.

You can get all builtin names with:

>>> import builtins>>> dir(builtins)

This includes everything from builtins.If you strictly only want the function names, just filter for them:

import typesbuiltin_function_names = [name for name, obj in vars(builtins).items()                           if isinstance(obj, types.BuiltinFunctionType)]

Resulting list in Python 3.6:

['__build_class__', '__import__', 'abs', 'all', 'any', 'ascii', 'bin', 'callable', 'chr', 'compile', 'delattr', 'dir', 'divmod', 'eval', 'exec', 'format', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', 'isinstance', 'issubclass', 'iter', 'len', 'locals', 'max', 'min', 'next', 'oct', 'ord', 'pow', 'print', 'repr', 'round', 'setattr', 'sorted', 'sum', 'vars', 'open']

If you want the functions objects, just change your code a little bit by selecting the 'obj' from the dictionary:

builtin_functions = [obj for name, obj in vars(builtins).items()                      if isinstance(obj, types.BuiltinFunctionType)]


>>> for e in __builtins__.__dict__:...     print(e)...__name____doc____package____loader____spec____build_class____import__absallanyasciibincallablechrcompiledelattrdirdivmodevalexecformatgetattrglobalshasattrhashhexidinputisinstanceissubclassiterlenlocalsmaxminnextoctordpowprintreprroundsetattrsortedsumvarsNoneEllipsisNotImplementedFalseTrueboolmemoryviewbytearraybytesclassmethodcomplexdictenumeratefilterfloatfrozensetpropertyintlistmapobjectrangereversedsetslicestaticmethodstrsupertupletypezip__debug__BaseExceptionExceptionTypeErrorStopAsyncIterationStopIterationGeneratorExitSystemExitKeyboardInterruptImportErrorModuleNotFoundErrorOSErrorEnvironmentErrorIOErrorWindowsErrorEOFErrorRuntimeErrorRecursionErrorNotImplementedErrorNameErrorUnboundLocalErrorAttributeErrorSyntaxErrorIndentationErrorTabErrorLookupErrorIndexErrorKeyErrorValueErrorUnicodeErrorUnicodeEncodeErrorUnicodeDecodeErrorUnicodeTranslateErrorAssertionErrorArithmeticErrorFloatingPointErrorOverflowErrorZeroDivisionErrorSystemErrorReferenceErrorBufferErrorMemoryErrorWarningUserWarningDeprecationWarningPendingDeprecationWarningSyntaxWarningRuntimeWarningFutureWarningImportWarningUnicodeWarningBytesWarningResourceWarningConnectionErrorBlockingIOErrorBrokenPipeErrorChildProcessErrorConnectionAbortedErrorConnectionRefusedErrorConnectionResetErrorFileExistsErrorFileNotFoundErrorIsADirectoryErrorNotADirectoryErrorInterruptedErrorPermissionErrorProcessLookupErrorTimeoutErroropenquitexitcopyrightcreditslicensehelp