1 print(abs(-5)) #都變成正數
1 #一個爲假,就爲假 # 0 空 None Flase 2 print(all([1,'a',0]))#False 3 # 列表中全部元素的布爾值爲真,最終結果才爲真 4 print(all('')) 5 # 傳給all的可迭代對象若是爲空,最終結果爲真
1 #但凡是有一個爲真,就爲真 2 # print(any([0,'',None,1])) 3 print(any([])) 4 # 傳給any的可迭代對象若是爲空,最終結果爲假
1 print(bin(11)) #10-2 2 print(oct(11)) #10-8 3 print(hex(11)) #10-16
1 print(bool(0))#0, None,空的布爾值爲假
1 res = '你好songhaiixng'.encode('utf-8') 2 print(res) #轉成了bytes類型 3 4 res = bytes('你好songhaixing',encoding='utf-8') 5 print(res) #同上面同樣
1 def func(): 2 pass 3 print(callable(func)) 4 print(callable('ss'.strip))#判斷 5 print(callable('dac'.split))#帶括號的均可以調用
1 print(chr(90))#按照表十進制轉化成字符 2 print(ord('x'))#。。。。。。轉化成數字
1 print(dir('song'))#查看某個對象能夠調用的方式
1 print(divmod(10,3))#(3,1) 10除於3餘1 2 print(divmod(10,2))#(5,0)
1 #將字符內的表達式拿出來運行一下,並拿到改表達式的計算結果 2 res = eval('2**3') #(去掉字符串) 3 print(res) 4 res = eval('[1,2,3,4,]') 5 print(res)
1 with open('db.txt','r',encoding='utf-8')as f: 2 f = f.read() #{'name':'song','pwd':'123'} 3 res = eval(f) #把這個字典拿出來了 4 print(res,type(res)) 5 print(res['pwd'])
1 fset = frozenset({1,2,3}) 2 3 #可變 4 s = {1,2,3,4} 5 s.add(5) 6 print(s) #{1, 2, 3, 4, 5} 可變
1 x = 1111111111111 2 print(globals())#查看全局做用域中名字於值得綁定關係 3 print(locals())
1 dic = {[1,2,3]:'a'}
1 hash([1,2,3,4,5,6,])#不可hash
1 def func(): 2 """ 3 幫助信息 4 :return: 5 """ 6 pass 7 print(help(func)) #顯示裏面的幫助信息 8 print(help(max))
1 len({'x':1,'y':2})#調用 __len__ 2 print({'x':1,'y':2}.__len__)
1 res = iter('song')#'song'.__iter__ 2 print(next(res))
1 print(pow(2,3,3))#2的3次方取餘
1 res = slice(1, 5, 2)#切片 2 3 l = [1, 2, 3, 4, 5, 6, 7, 8] 4 print(l[res]) #[2, 4] 5 6 t = (5, 14, 7, 8, 9, 5, 4, 2) 7 print(t[res]) #(14, 8)
1 print(sum([1,2,3,4,5])) #15
1 left = 'hello' 2 # right = (1,2,3,) #[('h', 1), ('e', 2), ('l', 3)] 3 right = {'x':1,'e':2} #[('h', 'x'), ('e', 'e')] 4 res = zip(left,right) 5 print(list(res))