Python 元組
描述
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