内置函数
1. abs(x) : 返回x的绝对值**
>>> abs(-1.3)
1.3
2. all(iterale) : 判断可迭代参数iterable中所有元素是否没有0、空、False是返回True,不是返回False
>>> all(['a','b','c'])
True
>>> all(['a','','c']) #元素中含有空
False
>>> all([1,2,3,0]) #元素中含有0
False
>>> all([True, False]) #元素中含有False
False
>>> all([]) #空列表为True
True
>>> all(()) #空元祖为True
True
>>> all({}) #空字典为True
True
3. any(iterable) : 判断可迭代参数iterable是否全为0、空、False,是则返回True,否则返回False
>>> any(['a','b','c'])
True
>>> any(['a','','c']) #元素中含有空但不全为空
True
>>> any([1,2,0]) #元素中含有0但不全为0
True
>>> any([False,True]) #元素中含有False但不全为False
True
>>> any([0,0]) #元素全为0
False
>>> any([]) #空列表
False
>>> any(()) #空元祖
False
>>> any({}) #空字典
False
4. basestrinf() : 方法是 str 和 unicode 的超类(父类),也是抽象类,因此不能被调用和实例化,但可以被用来判断一个对象是否为 str 或者 unicode 的实例,isinstance(obj, basestring) 等价于 isinstance(obj, (str, unicode))。
>>> isinstance("abc",str)
True
5. bin(x) : 返回整数或长整数的二进制
>>> bin(8)
'0b1000'
>>> bin(100)
'0b1100100'
6. bool() : 将参数转换为布尔类型,没有参数返回false。 bool是int子类
>>> bool() #没有参数
False
>>> bool(0)
False
>>> bool(1)
True
7. bytearray() : 返回一个新字节数组,这个数组的元素是可变的,每个元素的范围为[0.256]
>>> bytearray(3)
bytearray(b'\x00\x00\x00')
>>> bytearray([1,2,3,4])
bytearray(b'\x01\x02\x03\x04')
>>> bytearray('abc','utf-8')
bytearray(b'abc')
8. callable() : 检查一个对象是否是可调用的
bytearray(b'abc')
>>> callable(abs)
True
>>> callable(0)
False
9. chr(x) : x为一个在[0,256)之间的整数,可以是十进制和十六进制,返回一个对应的字符
>>> chr(0x30)
'0'
>>> chr(48)
'0'
10 . cmp(x,y) : 若x<y,返回-1,若x == y ,返回0,若x > y,返回1
11. complex() : 创建复数
>>> complex(3,4)
(3+4j)
>>> complex(2)
(2+0j)
>>> complex("1")
(1+0j)
>>> complex("1+2j")
(1+2j)
>>>
12. dict() : 创建一个字典
>>> dict(a='a', b