标签: python loops vector
我想制作一个矢量的正方形,例如n = (1,2,3,4,5,6,7,8,9,10),并将其作为解n = (1,4,9,16, 25.36,49,64,81,100)
n = (1,2,3,4,5,6,7,8,9,10)
n = (1,4,9,16, 25.36,49,64,81,100)
答案 0 :(得分:1)
您需要使用列表理解:
n = (1,2,3,4,5,6,7,8,9,10) new_n = tuple(pow(i, 2) for i in n)
输出:
(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)