Python-tuple-len

提供:Dev Guides
2020年6月22日 (月) 22:36時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

Python Tuple len()メソッド

説明

Pythonタプルメソッド* len()*は、タプル内の要素の数を返します。

構文

以下は* len()*メソッドの構文です-

len(tuple)

パラメーター

  • tuple -これは、要素の数がカウントされるタプルです。

戻り値

このメソッドは、タプル内の要素の数を返します。

次の例は、len()メソッドの使用法を示しています。

#!/usr/bin/python

tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc')
print "First tuple length : ", len(tuple1)
print "Second tuple length : ", len(tuple2)

上記のプログラムを実行すると、次の結果が生成されます-

First tuple length :  3
Second tuple length :  2