1
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 3 エンジニア認定基礎試験 合格に向けて part10 (データ型まとめ)

1
Posted at

Python データ型まとめ(基礎試験向け)

記法例 可変性 順序 重複 代表的操作・特徴
リスト [1, 2, 3, 3] ミュータブル あり あり append(), extend(), pop(), スライス可
タプル (1, 2, 3) イミュータブル あり あり unpack, インデックス指定可
集合 {'a', 'b', 'a'} or set([1,2,2]) ミュータブル なし なし add(), remove(), 集合演算(&
辞書 {'key': 'value'} ミュータブル なし キー不可重複 keys(), values(), items(), 代入可

補足

  • リスト: 順序が大事、重複もOK
  • タプル: 順序は大事だけど不変(書き換え不可)
  • 集合: 順序は関係なし、重複は自動で削除
  • 辞書: キーはユニーク、値は自由。順序は Python 3.7 以降は保持されるけど、基本的にはキーでアクセス

💡 覚え方のコツ

  • 「順序重視?」 → リスト・タプル
  • 「重複NG?」 → 集合・辞書キー
  • 「書き換えOK?」 → リスト・集合・辞書(タプルはNG)
1
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
1
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?