power2 = [] for i in range(1,10): power2.append(i*i) print(power2)
输出结果:
[1, 4, 9, 16, 25, 36, 49, 64, 81]
方法二:
squares = [x**2 for x in range(1,10)] print(squares)
输出结果为:
[1, 4, 9, 16, 25, 36, 49, 64, 81]
2024-02-28 22:30:52
power2 = [] for i in range(1,10): power2.append(i*i) print(power2)
输出结果:
[1, 4, 9, 16, 25, 36, 49, 64, 81]
方法二:
squares = [x**2 for x in range(1,10)] print(squares)
输出结果为:
[1, 4, 9, 16, 25, 36, 49, 64, 81]