Python list([]) and []

后端 未结 4 1602
时光取名叫无心
时光取名叫无心 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:53

    oldchain = list(chain)
    

    oldchain points to a new list that is not chain (not the same object) but has the same contents.
    *As other answers have mentioned, this is makes oldchain a "shallow copy" of chain.

    oldchain = chain
    

    oldchain just points to chain, both point to same object

    However, note that oldchain = [] and oldchain = list() are functionally the same since both are creating an empty list. It becomes different when other references (ie. chain) are involved.

提交回复
热议问题