- 3

How can I count the number of words in a sentence,like in this a=can you teach me?

21st Jun 2021, 3:22 PM
Vaibhav Tiwari
7 odpowiedzi
0
Vishal Tiwari Try this↓ Num=len(input().split()) print(Num)
21st Jun 2021, 3:28 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 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 
21st Jun 2021, 3:30 PM
SammE
SammE - avatar
+ 1
It is easy, Like this: can-1 you-2 teach-3 me-4 Use for loop
21st Jun 2021, 3:25 PM
Shadoff
Shadoff - avatar
+ 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)
21st Jun 2021, 3:36 PM
Shadoff
Shadoff - avatar
0
😁not like that
21st Jun 2021, 3:26 PM
Vaibhav Tiwari
0
I want to count this in code and want an output 4 can you teach me =4
21st Jun 2021, 3:26 PM
Vaibhav Tiwari
0
Thanks it worked
21st Jun 2021, 3:30 PM
Vaibhav Tiwari