print( all([1,-5,3]) )
print( any() )
a= ascii([1,2,"開外掛程式開外掛程式"])
print(type(a),[a])
print(bin(2555))
print(bool(0))
a = bytes('abcde',encoding='utf-8')
print(a.capitalize(),a)
b = bytearray('abcde',encoding='utf-8')#可修改字串
print(b[0])
b[1]=100
print(b)
print(callable())#可呼叫與否,後邊可加括號的為可呼叫
print(chr(87))
print(ord('w'))
code = 'for i in range(10):print(i)'
c = compile(code,'','exec')
exec(c)
code = '1+3/2*6'
c1 = compile(code,'','eval')
print(c1)
print(eval(c1))
a={}
print(dir(a))#dir,顯示類的所有方法
print(divmod(5,2))
#eval(),將字串轉為字典
#exec()將字串轉為可執行**
def sayhi(n):
print(n)
for i in range(n):
print(i)
sayhi(3)
#匿名函式
(lambda n:print(n))(5)
calc =lambda n:print(n)
calc(6)
res=filter(lambda n:n>5,range(10))
for i in res:
print(i)
res2 = map(lambda n:n*n,range(10))#[i*i for i in range(10)]
for i in res2:
print(i)
import functools
res3 = functools.reduce(lambda x,y:x+y,range(10))
print(res3)
a =frozenset ([1,4,33,4,5,6,7,5,8])#不可變列表
def test():
local_var =333
print(locals())
test()
print(globals())#返回當前程式所有的變數,以key-value形式表現
print(globals().get('local_var'))
print(hex(255))#轉成十六進製制
print(oct(9))#轉成八進位制
print(pow(2,5))
print(type(repr(123)),repr(123))#轉成字串物件
print(round(1.3364,2))#保留幾們小數
d = range(20)
print(d)
print(d[slice(1,5)])
a =
print(sorted(a.items()))#排完序後變成列表
print(sorted(a.items(),key=lambda x:x[1]))#按value排序
a = [1,2,3,4,5,6]
b =[ 'a','b','c','d','e']
print(zip(a,b))
for i in zip(a,b):
print(i)
#__import__('decorator4')#引用字串方式名
Linux內建函式練習
1 去目錄下複製檔案 root file ip.txt到自己目錄下,統計第一列 用空格隔開 ip的出現的頻率。awk nr 1end ip.txt 2 用awk 計算1 2 3 100的累計值 awk begin 3 用awk 寫入 shell 指令碼中,實現九九乘法表的列印 awk beginpr...
內建高階函式練習
332.31321 0 0 1 1 from functools import reduce def str2int s def char2int ch c print c return c ch def fun n1,n2 return n1 10 n2 return reduce fun,map...
函式 內建函式 匿名函式 相關練習
4,用map來處理字串列表,把列表中所有人都變成sb,比方alex sb name oldboy alex wusir print list map lambda a a sb name 5.用map來處理下述l,然後用list得到乙個新的列表,列表中每個人的名字都是sb結尾 l print lis...