![]() |
VOOZH | about |
The string len() function returns the length of the string. In this article, we will see how to find the length of a string using the string len() method.
Example:
4 0 1
len(string)
String: string of which you want to find the length.
It returns an integer which is the length of the string.
The len() method is used to find the length of an object in Python. By using len(), we can find the length of strings and lists. In this example, we are finding the length of a string.
In this example, we are counting the length of the tuples and list.
3 4
In this example, we are using len() with a boolean value and find TypeError as a result.
Output
TypeError: object of type 'bool' has no len()In this example, we are using Python len() with dictionaries and sets to find the length of dictionary and set.
2 4
In this example, we are using len() to find the length of custom objects and to find the length of an object in Python.
12
In this example, we are using the len() function to find the length of the range() function.
9
In this article, we have covered about Python string len() function and discussed its working. len() function is used to find the length of a string. It is a very common yet important function of string methods.
Read More String Methods