列表解析式和普通for循环运行效率对比
运行时间差不多,但是列表解析式的写法更加简洁。实验代码见下L = []d=[]n=10000import timest=time.time()for i in range(1,n): L.append(i**2)ed=time.time()print(ed-st)st=time.time()d = [ i**2 for i in range(1,n)]ed=time.time()print(ed-st)0.00299167633056640620.0029928