Python元组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