全局函数
import builtins
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’, ‘ModuleNotFoundError’,
‘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’, ‘breakpoint’,
‘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’]
1.abs() #求绝对值
a=-1
abs(a) 结果 1
2.all() #判断可迭代对象中的元素是否不为0,空,None,False,返回值是True,Flase。有任意一个元素为假,则为假
注:空的可迭代对象返回值True
all([‘a’, ‘b’, ‘c’, ‘d’]) #列表元素都不为空或0
True
all([‘a’, ‘b’, ‘’, ‘d’]) #列表存在一个为空的元素
False
all([0, 1,2, 3]) #列表存在一个为0的元素
False
all([]) #空列表
True
all(()) # 空元组
True
3.any() #判断可迭代对象不全为0,空,None,False,返回值是True,Flase。有任意一个元素为真,则就为真
any([‘a’, ‘b’, ‘c’, ‘d’]) # 列表元素都不为空或0
True
any([‘a’, ‘b’, ‘’, ‘d’]) # 列表元素至少有一个为真
True
any([0, ‘’, False]) # 列表元素全为0,’’,false
False
any([]) # 空列表
False
any(()) # 空元组
False
4.ascii() #返回一个表示对象的字符串,如果参数是ascii字符,则返回一个字符串对象;如果参数不是ascii字符,则返回含有\u \U x的字符串对象
ascii(“my name is python”)
“‘my name is python’”
“’\u4e2d\u56fd’”
5.bin() #返回一个整型的二进制形式
‘0b111’
6.bool() #将给定参数转换为布尔类型,如果没有参数,返回 False
bool(0)
False
bool(’’)
False
bool(None)
False
bool(False)
False
bool(1)
True
7.bytearray() #返回一个新的字节数组。这个数组里的元素是可变的,并且每个元素的值范围: 0 <= x <256
bytearray()
bytearray(b’’)
bytearray([1,2,3])
bytearray(b’\x01\x02\x03’)
bytearray(‘name’,‘utf-8’)
bytearray(b’name’)
8.bytes() #返回一个新的字节对象,该对象是一个 0 <= x < 256 区间内的整数不可变序列。它是 bytearray 的不可变版本
bytes()
b’’
bytes([1,2,3])
b’\x01\x02\x03’
bytes(‘name’,‘utf-8’)
b’name’
bytes(‘name’,‘ascii’)
b’name’
9.callable() #检查一个对象是否是可调用的。如果返回 True,object 仍然可能调用失败;但如果返回 False,调用对象 object 绝对不会成功。
callable(0)
False
callable(“name”)
False
def add(a, b):
… return a + b
…
callable(