Built-in Functions
The
dir
function is a built-in function: it
lives in the built-in namespace. Applying the LGB rule means that the
function is always available, and that no import
statement is needed to access it.[54]
You’ve already encountered many of the built-in functions, such
as len
, open,
type
, list
,
map
, range
,
reload
. You can find them listed with the standard
exceptions in the _
_builtins
__ namespace:
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'EOFError',
'Ellipsis','Exception', 'FloatingPointError', 'IOError', 'ImportError',
'IndexError','KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError',
'NameError','None', 'OverflowError', 'RuntimeError', 'StandardError',
'SyntaxError','SystemError', 'SystemExit', 'TypeError', 'ValueError',
'ZeroDivisionError','__debug__', '__doc__', '__import__', '__name__', 'abs',
'apply', 'callable','chr', 'cmp', 'coerce', 'compile', 'complex', 'delattr',
'dir', 'divmod', 'eval','execfile', 'filter', 'float', 'getattr', 'globals',
'hasattr', 'hash', 'hex','id', 'input', 'int', 'intern', 'isinstance',
'issubclass', 'len', 'list','locals', 'long', 'map', 'max', 'min', 'oct',
'open', 'ord', 'pow', 'range', 'raw_input', 'reduce', 'reload', 'repr',
'round', 'setattr', 'slice', 'str','tuple', 'type', 'vars', 'xrange']
Conversions, Numbers, and Comparisons
A few functions are used for converting between
object
types. We’ve already seen str
, which takes anything and returns a string representation of ...
Get Learning Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.