现在位置: 首页 > Python 基础教程 > 正文

Python Tuple(元组) len()方法

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

Python 元组Python 元组