标签:div code turn agg nbsp not 子类 for 表示
前言:Python的内建函数为编程提供了很大的方便,为方便以后的学习,在这里对Python 3.x的内建函数做一个相对完整的总结
1 print(abs(-1)) 2 print(abs(-10.01)) 3 print(abs(3+4j)) #返回复数的大小
特别注意:
(1) iterable一般为列表或元组
1 print(all([1,2,-5,‘agg‘])) 2 print(all((0,‘‘,True)))
(2) 空元组和空列表返回True
1 print(all([]))#空列表 2 print(all(()))#空元组
(3) all(iterable)等价于:
1 def all(iterable): 2 for element in iterable: 3 if not element: 4 return False 5 return True
特别注意:
(1) iterable一般为列表或元组
1 print(any([0,1,2,3])) 2 print(any((0,‘‘,False)))
(2) 空列表和空元组返回False
1 print(any(()))#空元组 2 print(any([]))#空列表
(3) any(iterable)等价于:
1 def any(iterable): 2 for element in iterable: 3 if element: 4 return True 5 return False
特别注意:
如果objiect对象中含有非ASCII字符,则通过repr()返回使用\x,\u或\U编码的字符串
1 number=1234 2 name=‘Tomwenxing‘ 3 location=‘杭州市‘ 4 print(ascii(number),type(ascii(number))) 5 print(ascii(name),type(ascii(name))) 6 print(ascii(location),type(ascii(location)))
1 print(bin(2),type(bin(2))) 2 print(bin(10)) 3 print(bin(20))
[注]:bool是int的子类
1 print(bool()) 2 print(bool(1)) 3 print(bool([1,2,3,4])) 4 print(issubclass(bool,int))#判断bool是否是int的子类
标签:div code turn agg nbsp not 子类 for 表示
原文地址:http://www.cnblogs.com/duwenxing/p/7407410.html