Python list([]) and []

后端 未结 4 1596
时光取名叫无心
时光取名叫无心 2020-12-02 00:30
from cs1graphics import *
from math import sqrt

numLinks = 50
restingLength = 20.0
totalSeparation = 630.0
elasticityConstant = 0.005
gravityConstant = 0.110
epsilo         


        
4条回答
  •  心在旅途
    2020-12-02 00:55

    It is true that list([]) is functionally equivalent to [], both creating a new empty list.

    But x = list(y) is not the same as x = y. The formers makes a shallow copy, and the latter creates a new reference to the existing list.

    Note that list([]) is inefficient -- it creates a new empty list (by doing []), then copies it, resulting with another empty list (by doing list(...)), then deallocates the original, unreferenced, list.

提交回复
热议问题