python的内置函数(built-in functions)
(2011-08-17 15:42:17)
标签:
杂谈 |
分类: Python |
python的内置函数可以直接调用,无需import。有很多
我在平时常用到的,
int()将字符串或者小数转换成整数
str()将其他类型转换是字符型
len(X)返回X的长度。The argument may be a sequence (string, tuple or list) or a mapping (dictionary).
print()输出
type(X)返回X的数据类型
open(f)打开一个文件f并返回文件类型的对象。 和file()相似。
在python2.7.2 doc中可以查到每个函数的详细用法。
|
|
Built-in Functions |
|
|
想要查所有内置函数名可以在python命令行方式中如下输入
>>>dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError',
'BaseException', 'DeprecationWarning', 'EOFError', 'Ellipsis',
'EnvironmentError', 'Exception', 'False', 'FloatingPointError',
'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError',
'ImportWarning', 'IndentationError', 'IndexError', 'KeyError',
'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError',
'None', 'NotImplemented', 'NotImplementedError', 'OSError',
'OverflowError', 'PendingDeprecationWarnin