How to fill a list

后端 未结 5 563
深忆病人
深忆病人 2021-01-05 03:26

I have to make a function that takes an empty list as first argument and n as secound argument, so that:

L=[]
function(L,5)
print L
returns:
[1,2,3,4,5]
         


        
5条回答
  •  一整个雨季
    2021-01-05 03:49

    And a bit shorter example of what you want to do:

    l = []
    l.extend(range(1, 5))
    l.extend([0]*3)
    
    print(l)
    

提交回复
热议问题