List assignment with [:]

后端 未结 6 1060
小蘑菇
小蘑菇 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:04

    list[:] will only work if there is already an object named list that allows slice assignment.

    Also, you shouldn't name variables list because there is a built-in named list which is the list type itself.

提交回复
热议问题