Python Tuple len() Method

Python 元组Python Tuple


Description

The Python tuple len() function calculates the number of elements in a tuple.

Syntax

Syntax of the len() method:

len(tuple)

Parameters

  • tuple -- The tuple to be calculated.

Return Value

The function returns the number of elements in the tuple.

Example

The following example demonstrates how to use the len() function:

#!/usr/bin/python

tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc')

print "First tuple length : ", len(tuple1);
print "Second tuple length : ", len(tuple2);

The output of the above example is:

First tuple length :  3
Second tuple length :  2

Python 元组Python Tuple

Other Extensions