Talk is cheap, show me the code.
if __name__ == '__main__':
"""abs() 取绝对值"""
assert abs(-1) == 1
"""all(iterator) 迭代对象中 全部为True 才返回True"""
assert all([0, '', None, False]) is False
assert all([]) is True
assert all(()) is True
"""any(iterator) 迭代对象中 有一个元素为True 就返回True"""
assert any([0, '', None, False, True]) is True
assert any([]) is False
assert any(()) is False
"""basestring() 方法是 str 和 unicode 的超类(父类)"""
assert isinstance('Hello', (str, unicode))
assert isinstance('Hello', basestring)
"""bin()返回一个整数int或者长整数long int 的二进制表示"""
assert bin(10) == '0b1010'
assert isinstance(bin(20), basestring)
"""将给定参数转换为bool类型"""
assert not bool()
assert not bool(0)
assert bool(1)
assert issubclass(bool, int) # bool 是int的子类
"""bytearray() 返回一个新的字节数组"""
assert bytearray() == bytearray(b'')
assert bytearray([1, 2, 3]) == bytearray(b'\x01\x02\x03')
assert bytearray('hello', 'utf-8') == bytearray(b'hello')
"""callable() 检查函数是否是可调用的"""
assert not callable(0)
assert not callable('string')
"""chr() 返回整数对应的ASCII字符"""
assert chr(0x61) == 'a'
assert chr(97) == 'a'
"""classmethod 装饰类函数不需要实例化"""
pass
"""cmp(x, y) 比较两个对象"""
assert cmp(80, 100) == -1
assert not cmp(80, 80)
assert cmp(100, 80) == 1
"""compile() 将一个字符串编译为字节代码"""
"""complex() 创建一个复数"""
"""delattr() 删除属性"""
# delattr(object, name)
"""dict() 创建一个字典"""
assert dict(a='a', b='b', c='c') == {'a': 'a', 'b': 'b', 'c': 'c'}
assert dict(zip(['a', 'b', 'c'], [1, 2, 3])) == {'a': 1, 'b': 2, 'c': 3}