python Modifying slice of list in function

前端 未结 3 645
一向
一向 2021-01-19 02:43

Consider the following piece of code:

def func1(a):
    a[:] = [x**2 for x in a]

a = range(10)
print a  #prints [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
func1(a[:5])
         


        
3条回答
提交回复
热议问题