Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Tuple len() method

Python Tuple len() method

Python TuplePython Tuple


Description

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

Syntax

len() method syntax:



len(tuple)

Parameters

Return Value

The function returns the number of elements in the tuple.

Example

The following example shows 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 TuplePython Tuple