Creating an empty list in Python

前端 未结 5 1412
长情又很酷
长情又很酷 2020-11-28 17:17

What is the best way to create a new empty list in Python?

l = [] 

or

l = list()

I am asking this because

5条回答
  •  忘掉有多难
    2020-11-28 18:11

    Just to highlight @Darkonaut answer because I think it should be more visible.

    new_list = [] or new_list = list() are both fine (ignoring performance), but append() returns None, as result you can't do new_list = new_list.append(something).

提交回复
热议问题