1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでリストの作成・編集をしてみよう

1
Posted at

はじめに

未来電子テクノロジーでインターンをしている宮﨑です。
pythonでハッカーランクに挑戦中なのですが、easyレベルでも苦戦中…
めげずに頑張ります…!

今回はリストの基本的なところをまとめました。
もし誤りがあれば修正するのでどんどん指摘してください。

リストの作成・編集

リストからリスト(複数の要素)を取り出す

リスト[インデックスの始点:インデックスの終点+1]と記述する。

(例1)インデックス2~4の要素を取り出す
リスト名[2:5]

(例2)インデックス2~終点
リスト名[2:]

(例3)始点~インデックス5
リスト名[:6]

(例4)インデックス3~終点の2つ前
リスト名[3:-1]

リストの要素を上書きする

リスト名[インデックス] = 値

要素を追加する

リスト名.append(追加する要素)

要素を削除する

del リスト名[インデックス]

2次元配列

リストの要素をリストにする。

[[1,2,3],[4,5,6]]

まとめ

リストの書き方はわかってきました。
次回はエラーの原因をまとめてみようかなと思っています。

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?