Python List len()メソッド

Python 列表Python リスト


説明

len() メソッドはリストの要素数を返します。

構文

len() メソッドの構文:

len(list)

パラメータ

  • list -- 要素数を計算するリスト。

戻り値

リストの要素数を返します。

例

以下の例は、len() 関数の使用方法を示しています:

#!/usr/bin/python

list1, list2 = [123, 'xyz', 'zara'], [456, 'abc']

print "First list length : ", len(list1);
print "Second list length : ", len(list2);

上記の例の出力結果は次のとおりです:

First list length :  3
Second lsit length :  2

Python 列表Python リスト

その他の拡張