回答編集履歴
2
追記
answer
CHANGED
|
@@ -27,4 +27,11 @@
|
|
|
27
27
|
|
|
28
28
|
> タプルはリストと似ていますが、たいてい異なる場面と異なる目的で利用されます。タプルは不変型 (immutable) で、複数の型の要素からなることもあり、要素はアンパック(この節の後半に出てきます)操作やインデックス (あるいは namedtuples の場合は属性)でアクセスすることが多いです。一方、リストは変更可能 (mutable) で、要素はたいてい同じ型のオブジェクトであり、たいていイテレートによってアクセスします。
|
|
29
29
|
|
|
30
|
-
引用元: [Python チュートリアル » タプルとシーケンス](https://docs.python.jp/3/tutorial/datastructures.html#tuples-and-sequences)
|
|
30
|
+
引用元: [Python チュートリアル » タプルとシーケンス](https://docs.python.jp/3/tutorial/datastructures.html#tuples-and-sequences)
|
|
31
|
+
|
|
32
|
+
参考
|
|
33
|
+
---
|
|
34
|
+
英語ですけれど、深まった議論がなされています。
|
|
35
|
+
[Stack Overflow - What's the difference between lists and tuples?](https://stackoverflow.com/questions/626759/whats-the-difference-between-lists-and-tuples)
|
|
36
|
+
|
|
37
|
+
> Apart from tuples being immutable there is also a semantic distinction that should guide their usage. Tuples are heterogeneous data structures (i.e., their entries have different meanings), while lists are homogeneous sequences. **Tuples have structure, lists have order.**
|
1
追記
answer
CHANGED
|
@@ -23,4 +23,8 @@
|
|
|
23
23
|
- 同じ型のオブジェクトを扱う ⇒ リスト
|
|
24
24
|
- 違う型のオブジェクトを扱う ⇒ タプル
|
|
25
25
|
|
|
26
|
-
リストは配列、タプルは構造体に近い使われ方をしているように思います。
|
|
26
|
+
リストは配列、タプルは構造体に近い使われ方をしているように思います。
|
|
27
|
+
|
|
28
|
+
> タプルはリストと似ていますが、たいてい異なる場面と異なる目的で利用されます。タプルは不変型 (immutable) で、複数の型の要素からなることもあり、要素はアンパック(この節の後半に出てきます)操作やインデックス (あるいは namedtuples の場合は属性)でアクセスすることが多いです。一方、リストは変更可能 (mutable) で、要素はたいてい同じ型のオブジェクトであり、たいていイテレートによってアクセスします。
|
|
29
|
+
|
|
30
|
+
引用元: [Python チュートリアル » タプルとシーケンス](https://docs.python.jp/3/tutorial/datastructures.html#tuples-and-sequences)
|