Raising elements of a list to a power

前端 未结 8 1951
傲寒
傲寒 2020-12-17 18:02

How can I raise the numbers in list to a certain power?

8条回答
  •  无人及你
    2020-12-17 18:43

    You can simply do:

    numbers=[1,2,3,4,5,6,7,8,9]
    numbers3 = []
    for n in numbers:
        numbers3.append(n**3)
    
    print('Original list:', numbers)
    print('Cubic list:', numbers3)
    

提交回复
热议问题