想得到1-9的每个整数的平方,并将结果放在列表中打印出来;
作者:互联网
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]
标签:25,平方,squares,列表,64,print,想得到,81,power2 来源: https://www.cnblogs.com/banzisky/p/15125375.html