len() function in python – Get string length in python

len() function in python returns the length of the string. lets see an example on how to get length of a string in python with the help of length function – len().

Syntax for len() function in python – string length function :

len( str )


Example of len() function in python for strings :

Length function in python –len()  returns the length of the string in python, lets see with an example

str = "Beauty of democracy!!";
print "Length of the string is : ", len(str)

The output will be

Length of the string is: 21


Example of len() Function for list in python – number of elements in the list:

Length function – len()  also returns the number of elements in the list. Lets see with an example


print "Length of the first List : ", len(List1)
print "Length of the second List : ", len(List2)

The output will be

Length of the first List : 4
Length of the second List : 2

length of the string in columns of dataframe in python can be referred here

previous len() function in python                                                                                                                 next len() function in python