How to append to the end of an empty list?

前端 未结 8 1170
终归单人心
终归单人心 2020-11-27 13:13

I have a list:

list1=[]

the length of the list is undetermined so I am trying to append objects to the end of list1 like such:



        
8条回答
  •  悲哀的现实
    2020-11-27 13:38

    append returns None, so at the second iteration you are calling method append of NoneType. Just remove the assignment:

    for i in range(0, n):
        list1.append([i])
    

提交回复
热议问题