Python: what is the difference between (1,2,3) and [1,2,3], and when should I use each?

后端 未结 17 2172
旧巷少年郎
旧巷少年郎 2020-12-29 01:24

In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.

When should I use one or the other, and why?

17条回答
  •  滥情空心
    2020-12-29 01:38

    (1,2,3) is a tuple and [1,2,3] is a list. You either of the two represent sequences of numbers but note that tuples are immutable and list are mutable Python objects.

提交回复
热议问题