0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pythonイテラブルとシーケンスの違い

0
Last updated at Posted at 2026-01-12

Pythonの学習を進める中で、関数やメソッドの説明を読むたびにイテラブル(iterable)とシーケンス(sequence)の違いを調べているので自分なりにまとめておきます。
理解することによって言語の学習が進みやすくなるかも...

定義

それぞれの定義は
・iterable → 順番に取り出せるもの
・sequence → 順番に取り出せて、番号(インデックス)でも取り出せる1もの
という意味。
つまりsequenceはiterableの中に含まれるということらしい。

詳しく

iterableの例

list,tuple,set,dict,strなどがiterabkeに含まれる。全部for 構文で回せる。

[1, 2, 3]          # list
(1, 2, 3)          # tuple
{"a", "b", "c"}    # set
{"a": 1, "b": 2}   # dict(キー)
"hello"            # str
range(5)           # range

for 構文で回すとは、例えば下記のようなコードを書くと、要素を順番にiに取り出しながら繰り返し処理ができる。

lst = ["a","b","c"]
for i in lst:
    print(i)

sequense の例

list,tuple,str,rangeなどがsequenceに当てはまる。
逆に辞書型(dict)はindexを使って指定ができないからsequenceではない。

[1, 2, 3]     # list
(1, 2, 3)     # tuple
"abc"         # str
range(5)      # range

  1. そもそもiterable というのがiterate(反復する)が語源らしい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?