サクサク読めて、アプリ限定の機能も多数!
タグをすべて表示
タグの絞り込みを解除
>>> a = [1,2,3,4,5,6,7,8,9] >>> a[1:8:2] # インデックス1〜7の要素を2ステップで [2, 4, 6, 8]
作成済みのリストに指定した値と同じ要素が含まれているかどうか、含まれている場合の要素の数や要素のインデックスを取得する方法について解説します。要素が含まれているかどうかの確認には in 演算子、要素の数を確認するには count メソッド、インデックスを確認するには index メソッドを使用します。
リストの要素の削除については以下の記事を参照。 関連記事: Pythonでリスト(配列)の要素を削除するclear, pop, remove, del なお、リストは異なる型のデータを格納可能で、厳密には配列とは異なる。配列を扱いたい場合はarray(標準ライブラリ)やNumPyを使う。 関連記事: Pythonのリストと配列とnumpy.ndarrayの違いと使い分け リストの末尾に要素を追加: append() リストのappend()メソッドで、末尾(最後)に要素を追加できる。先頭など、末尾以外の位置に追加したい場合は後述のinsert()を使う。
ランキング
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く