Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()
2018-06-15 16:35 改改~_~ 阅读(305) 评论(0) 编辑 收藏 举报print('abs():输出绝对值,是absolute的缩写--------------') print(abs(-1)) print('all()与any()---------------------------') #all都为真时才为真,但是空的为真,any()有一个为真时就是真的 jo1_list=[1,2,3,4,5,6,7] jo2_list=['',2,3,4,5,7] jo4_list=[0,2,3,4,5,6,7] jo5_list=[False,2,3,4,5,6,7] jo6_list=[] jo7_list=[0,'',False] print('all()列表元素不为空和零',all(jo1_list)) print('all()列表元素包含一个空',all(jo2_list)) print('all()列表元素包含一个0',all(jo4_list)) print('all()列表元素包含一个False',all(jo5_list)) print('all()列表元素为空',all(jo6_list)) print('all()列表元素为空、零和假',all(jo7_list)) print('any()列表元素不为空和零',any(jo1_list)) print('any()列表元素包含一个空',any(jo2_list)) print('any()列表元素包含一个0',any(jo4_list)) print('any()列表元素包含一个False',any(jo5_list)) print('any()列表元素为空',any(jo6_list)) print('all()列表元素为空、零和假',any(jo7_list)) print('ascii()-----------------------') print('参数为数字,返回字符串',ascii(10)) print('参数为字符串,返回字符串',ascii('jojojo')) print('参数为汉字,返回字符串',ascii('呵呵哒')) print('bin()是binary的缩写--------------------------') print(bin(1)) print(bin(10000**1000)) print('bool()---------') print(bool()) print(bool(0)) print(bool(1)) print(bool(2)) print('issubclass()---') class jo: pass class joo(jo): pass class jook: pass print(issubclass(joo,jo)) print(issubclass(jook,jo))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | >>>> bytearray( 'heheda' ) Traceback (most recent call last): File "<pyshell#28>" , line 1 , in <module> bytearray( 'heheda' ) TypeError: string argument without an encoding >>> bytearray(heheda) Traceback (most recent call last): File "<pyshell#29>" , line 1 , in <module> bytearray(heheda) NameError: name 'heheda' is not defined >>> bytearray( 'heheda' ,''utf - 8 ) SyntaxError: invalid syntax >>> bytearray( 'heheda' , 'utf-8' ) bytearray(b 'heheda' ) >>> bytearray( 'heheda' , 'gb2312' ) bytearray(b 'heheda' ) >>> bytearray( 'heheda' , 'BIG5' ) bytearray(b 'heheda' ) >>> bytearray( '呵呵哒' , 'BIG5' ) Traceback (most recent call last): File "<pyshell#34>" , line 1 , in <module> bytearray( '呵呵哒' , 'BIG5' ) UnicodeEncodeError: 'big5' codec can 't encode character ' \u54d2' in position 2 : illegal multibyte sequence >>> bytearray( '呵呵哒' , 'gb2312' ) bytearray(b '\xba\xc7\xba\xc7\xdf\xd5' ) >>> bytearray( '呵呵哒' , 'utf-8' ) bytearray(b '\xe5\x91\xb5\xe5\x91\xb5\xe5\x93\x92' ) >>> is SyntaxError: invalid syntax >>> isinstance (jojo, str ) Traceback (most recent call last): File "<pyshell#38>" , line 1 , in <module> isinstance (jojo, str ) NameError: name 'jojo' is not defined >>> isinstance ( 'jojo' , str ) True >>> isinstance ( 'jojo' , unicode ) Traceback (most recent call last): File "<pyshell#40>" , line 1 , in <module> isinstance ( 'jojo' , unicode ) NameError: name 'unicode' is not defined >>> isinstance ( 'jojo' , 'utf-8' ) Traceback (most recent call last): File "<pyshell#41>" , line 1 , in <module> isinstance ( 'jojo' , 'utf-8' ) TypeError: isinstance () arg 2 must be a type or tuple of types >>> isinstance ( 'jojo' , 'utf-8' ) |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步