The string length in Python
The Python len() method returns the total number of characters in a given string. The Python string length method is quite useful especially if your program allows the limited number of characters for a text field or some other case.
Syntax of Python length method
Following is the basic syntax of len() method:
A string length example
The example below shows how len() method of Python is used to return the total number of characters in the given string. For that, we have created a string variable and assigned it a value at the time of declaration.
After that, we used the print function to display the output. In the print function, we used the len method to return the total characters in that string variable.
#Python Strings methods
strmet = “This is string length lesson”
print (“The length of string is:”, len(strmet))
Output will be:
The length of string is: 28
Also see: Python String