- 1
[SOLVED] If we have given a string as a input and there is space between words.can we separate the words and print?
10 Respostas
+ 6
string = "hello Dharani"
string = string.split()
print(string)
>>>["hello", "Dharani"]
..string is now splitted into words separrated by comma
+ 2
Jayakrishna
for word in words:
print(word)
+ 1
In what language..? Pls Tag specific language...
It can done by Predefined functions for splitting words by a separator space..
For ex: in java
String s[] =in.nextLine(). split(" ");
s[] array stores input line separated by space into words.. 'in' is the Scanner object...
Ex: input
hello World and hi
s[0]= hello
s[1]=World
S[2]=and
S[3]=hi
+ 1
You need to give us more details. What language is this about?
And what exactly want to do with the words? (Just for output, you don't need to split.)
+ 1
Thank you for your replies
0
I have to slice the string and combine .is it possible?
0
If I give input string as "hello dharani" the output will print like "dharani hello" .I want to write it in python
0
words = "hello dharani"
words = words.split(" ")
counter = len(words) -1
min_index = 0
for i in range(len(words)-1,-1,-1) :
print(words[i],end=" ")
I tried... But It may be simplified...
Edit:
from below suggestions..
words = "hello dharani"
words = words.split(" ")
for word in reversed(words):
print(word, end=" ")
@Dharani Wel come. Hope it helped you..
0
for word in reversed(words):
...