pyhon BIF

来源:互联网 发布:js array 删除 编辑:程序博客网 时间:2024/06/05 17:52
 BIF(built-in functions) 顾名思义,就是内建函数。它们通常用来完成那些无法用Erlang完成的任务。比如将列表转换为元组或者获取当前的时间和日期。完成这些操作的函数,我们称之为BIF。
>>> dir<built-in function dir>>>> dir(__builtins__)['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']>>> help(input)Help on built-in function input in module builtins:input(prompt=None, /)    Read a string from standard input.  The trailing newline is stripped.    The prompt string, if given, is printed to standard output without a    trailing newline before reading input.    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.    On *nix systems, readline is used if available.>>> 

类型转换 :

有时候,可能需要执行的内置类型之间的转换。类型之间的转换,只需使用类名作为函数。

有几个内置的功能,从一种数据类型进行转换为另一种。这些函数返回一个表示转换值的新对象。

函 数 描述 int(x [,base]) 将x转换为一个整数。基数指定为base,如果x是一个字符串。 long(x [,base] ) 将x转换为一个长整数。基数指定为base,如果x是一个字符串。 float(x) 将x转换到一个浮点数。 complex(real [,imag]) 创建一个复数。 str(x) 转换对象x为字符串表示形式。 repr(x) 对象x转换为一个表达式字符串。 eval(str) 计算一个字符串,并返回一个对象。 tuple(s) 把s转换为一个元组。 list(s) 把s转换为一个列表。 set(s) 把s转换为一个集合。 dict(d) 创建一个字典。 d必须的(键,值)元组序列。 frozenset(s) 把s转换为冻结集。 chr(x) 整数转换为一个字符。 unichr(x) 整数转换为一个Unicode字符。 ord(x) 转换单个字符为整数值。 hex(x) 将整数转换为十六进制字符串。 oct(x) 将整数转换为以八进制的字符串。
0 0
原创粉丝点击