List assignment with [:]

后端 未结 6 1064
小蘑菇
小蘑菇 2020-11-29 09:42

What\'s the difference between

list = range(100)

and

list[:] = range(100)

in Python?

EDI

6条回答
  •  青春惊慌失措
    2020-11-29 10:06

    list[:] = range(100)
    

    won't work on uninitialized variable, as it is modifying it. The [:] specifies the whole list/touple.

提交回复
热议问题