Python - String Length


Advertisements

The Python len() function is used to find out the total number of characters in the string. Apart from Alphabets, any symbol, space, special character or number in the string is also considered as a character while finding out the length of the string. To add more to this, len() function is used to return the number of elements in an iterable. An iterable object can be any data structure like list, tuple, set, string and dictionary, etc.

Syntax


len(str)

Parameters

str Required. specify iterable like a string to find out total number of characters in it.

Example:

In the below example, len() function is used on the string to find out the total number of characters in it.

MyString = "Learn Python"
#Returns total number of characters in the string.
x = len(MyString)    
print(x)

Output

12

String Methods
Advertisements