一般写法 def count_list(std:list,tongji): i=0 for item in std: if item==tongji: i+=1 print(i) if __name__=='__main__': lists=[1,2,3,4,5,1,2,3,4,5,2,2,2,3,4] count_list(std=lists,tongji=2) 新写法, python 3.5 之后 def count_list(std:list,tongji): from collectio…
1. 列表 #以下三式等价 c = (a>b and a or b) c = a if a>b else b c = [b, a][a>b] 字符串拼接 ' + '.join('%s,%s'%(a,b) for a,b in zip(list('abc'), range(3))) 'a,0 + b,1 + c,2' 字符查找 'aa' in '大家aa' #True '大家aa'.find('大家') #0 for循环 from itertools import product resu…