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

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

    If you can find a solution that works with tuples, use them, as it forces immutability which kind of drives you down a more functional path. You almost never regret going down the functional/immutable path.

提交回复
热议问题