#方法1:传统方法import timet0=time.time()ind=[]for i in range(10000): sqr_values=i*i ind.append(sqr_values)t1=time.time()print(t1-t0)0.004066944122314453#方法2:列表推导式import timet0=time.time()sqr_value=[i*i for i in range(10000)]t1=time.time()print(t1-t0)0.0020749568939208984