操作 | 書き方 |
定義 | test = [] |
要素の追加 | test += ["xxxx","yyyy"] または test.extend(["xxxx","yyyy"]) |
要素の追加(途中) | test.insert(位置,"xxxx") |
要素の追加(末尾) | test.apend("xxxx") |
要素の変更 | test[2] = "yyyy" |
要素の変更(内包記法による複数要素更新) | test = [1,2,3] test2 = [x*2 for x in test] ※要素の中を全部2倍する |
要素の削除 | del test[x] ※値で削除したい場合はremoveを使う。test.remove("xxxx") |
参照 | test[x] |
要素にアクセス(ループ) | for item in test: . print (item) |
指定した要素が配列内に含まれるか | "xxxx" in test |
指定した要素のインデックスを調べる | test.index("xxxx") |