Python Forum

Full Version: calculating length of string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I think you don't need the length of string you want to calculate the digit in the length of string. 

you can use this code :-

your_string = 'qwertyuiop'
print len(str(len(your_string)))

Output:
2
you want to know the number of terms ???

for example :- 

s = python is a script language

then it should return 5

for that you can use this code 

print len(s.split(' '))

where s.split(' ') will proivde you  list (['python', 'is', 'a', 'script', 'language'])

and len(s.split(' ')) will return the number of terms in s (5)

try it it may help you 

thanks for reading my reply
Here is my solutions for your query :-

sentence = input('enter :-')
word_list = sentence.split(" ")
print (len(word_list))
Pages: 1 2