Moving around in a string
Cousin Stanley
CousinStanley at hotmail.com
Sun Dec 7 07:31:40 EST 2003
| words_within = sentence.split()
|
| word_count = 0
|
| for i in words_within:
| word_count = word_count+1
|
| print "There are", word_count, "words."
Ryan ....
You might also find the len() builtin function useful
to provide the length of a list or string ....
sentence = 'yo ho ho and a bottle of rum'
words = sentence.split()
word_count = len( words )
print word_count
--
Cousin Stanley
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list