- 3
How can I count the number of words in a sentence,like in this a=can you teach me?
7 Answers
0
Vishal Tiwari
Try thisâ
Num=len(input().split())
print(Num)
+ 2
The split method in Python splits a string into parts using a special delimiter.
a = 'Some text.'
print(len(a.split(' ')))
about split():
https://www.w3schools.com/python/ref_string_split.asp
http://net-informations.com/python/file/split.htmÂ
+ 1
It is easy,
Like this:
can-1
you-2
teach-3
me-4
Use for loop
+ 1
As an addition to the answers of Ëâ*°â˘.Ëâ*°⢠Mohan 333 â˘Â°*âË.â˘Â°*âË and Rostislav Khalilov , here is unusual way:
a='can you teach me'
print(a.count(' ')+1)
0
đnot like that
0
I want to count this in code and want an output 4
can you teach me =4
0
Thanks it worked