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

后端 未结 17 2165
旧巷少年郎
旧巷少年郎 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:33

    a = (1,2,3) is a tuple which is immutable meaning you can't add anything into a b = [1,2,3] is a list in python which is immutable meaning you can make changes into 'b' either delete or add numbers into it.

提交回复
热议问题