String is a group of characters. Python has built in function which calculates number of characters in a string. We can use len() function to find the length of a string. Space in a string is also considered as a character.
In this blog, we will ask user to enter any string then using the len() function to find the number of characters in a string.
Asking user to input any string. Using str variable to store the string entered by user
str = input('Please enter any string: ')
Using len(str) function to find number of characters in a string and assigning the value to l variable
l = len(str)
Displaying the result
print('Total length a string:%s'%l)
OUTPUT
Please enter any string: Pyhton is a programming language
Total length a string:32
Complete Code
str = input('Please enter any string: ')
l = len(str)
print('Total length a string:%s'%l)