Latest web development tutorials

Python Tuple(元組) len()方法

描述

Python 元組len() 函數計算元組元素個數。

語法

len()方法語法:

len(tuple1, tuple2)

參數

  • 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