What's the difference between list1 = [] list2 = [] and list1 = list2 = [] in python?

前端 未结 2 907
一向
一向 2021-01-22 17:01

I just started using python and I am trying to initialize two lists using list comprehensions. Like this

list1 = list2 = [0.0] * 57

When i do

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 17:18

    The first one sets list1 and list2 to both refer to the same list. The second one defines a new list for each name.

提交回复
热议问题