Python Forum
calculating length of string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: calculating length of string (/thread-2212.html)

Pages: 1 2


RE: calculating length of string - ankit - Mar-23-2017

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


RE: calculating length of string - ankit - Apr-12-2017

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


RE: calculating length of string - ankit - May-22-2019

Here is my solutions for your query :-

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