Python 3 - Tuple len() Method


Advertisements

Description

The len() method returns the number of elements in the tuple.

Syntax

Following is the syntax for len() method −

len(tuple)

Parameters

tuple − This is a tuple for which number of elements to be counted.

Return Value

This method returns the number of elements in the tuple.

Example

The following example shows the usage of len() method.

#!/usr/bin/python3

tuple1, tuple2 = (123, 'xyz', 'zara'), (456, 'abc')
print ("First tuple length : ", len(tuple1))
print ("Second tuple length : ", len(tuple2))

Result

When we run above program, it produces the following result −

First tuple length :  3
Second tuple length :  2
python_tuples.htm
Advertisements