Python元組len()
函式用於返回元組中的元素數量。
語法
以下是len()
函式的語法 -
len(tuple)
引數
返回值
以下範例顯示了len()
函式的用法 -
#!/usr/bin/python3
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