Quantcast
Channel: JS Tricks » Python
Viewing all articles
Browse latest Browse all 25

Python tuple len Method – len()

$
0
0

In this lesson we will learn about Python tuple len method. This len method will return the number of elements in the tuple.

Python tuple len Method

Python tuple len method is an effective way to get the number of elements in a tuple. The len method can also be used for getting number of elements in Dictionary and List.

Syntax

len( myTuple )

  • myTuple – that specific Tuple of which you want to get the number of elements.

This method will return the number of elements.

Examples

Here are some examples of Python tuple len method:

myTuple1 = ('apple', 'banana','lemon', 'orange')
myTuple2 = ('a','b','c','d','e','f')

print " Length of myTuple1 is : ", len( myTuple1 )
print " Length of myTuple2 is : ", len( myTuple2 )

If you run this script then the output will look like this:

Length of myTuple1 is :  4
Length of myTuple2 is :  6

You can also use the len() method for getting number of elements in Dictionary , List, even String.

The post Python tuple len Method – len() appeared first on JS Tricks.


Viewing all articles
Browse latest Browse all 25

Trending Articles