Python3 tuple.len()方法

len()方法返回在元组中的元素的数量。

语法

以下是 len() 方法的语法-
len(tuple)

参数

  • 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

上一篇: Python3列表 下一篇: Python3元组