How to append to the end of an empty list?

前端 未结 8 1172
终归单人心
终归单人心 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:42

    Like Mikola said, append() returns a void, so every iteration you're setting list1 to a nonetype because append is returning a nonetype. On the next iteration, list1 is null so you're trying to call the append method of a null. Nulls don't have methods, hence your error.

提交回复
热议问题