Length of string python | len python

To find length of string in python we use built-in function len().

The len() is used to find the length of the Object it can be string, tuple, list, dictionary, and set.

The detail of this function is as below

len() in Python

len() is a predefined function that returns the number of elements in the collection as integer values

Syntax

len(collection)

collection must be of sequence type

Python len() Example

python string length

finding a string length using len() is very simple you have to just pass the string inside len(). That will return a number of elements in the string.

len python: Example to find the length of tuple

As we find string length we can also find tuple length in python.

In the below example, two tuples tuple1 and tuple2 initialized and passed to len() to get tuples length.

len python: Example to find length of list python

Below two list list1 and list2 initialized. To find the length of list len() is used.

len python: Example to find length of dictionary python

We initialized a dictionary and find its length as below

len python: Example to find length of set python

Python set is initialized as below and len() is used to find its length.

What does len do in python

len() is a predefined function in python that is used to find the number of elements in sequenced collection type.