0

[Solved] Operations on strings

If I had a string that consists of multiple words seperated by spaces, would it be possible to operate on each word seperately; and is there a function for reversing a string?

29th Dec 2019, 8:30 PM
Issa
6 ответов
+ 3
You can split the words in a sentence with split() function of string object in python. Save the result in a list then you can do whatever you want to them
29th Dec 2019, 8:35 PM
Abdol Hashimi
Abdol Hashimi - avatar
+ 2
Phantom split() function is build-in and you can call it for Strings ex:- "hey there".split(" ") It will return two strings("hey"," there")
29th Dec 2019, 8:43 PM
Abdol Hashimi
Abdol Hashimi - avatar
+ 1
Thank you so much for your help. ~ swim ~
29th Dec 2019, 8:48 PM
Issa
+ 1
Now it's clear. Thank you so much. Saboor Hakimi 🇦🇫
29th Dec 2019, 8:48 PM
Issa
+ 1
Just to add to what other people have posted (might be of interest to someone):- print("hello world =>", *"hello world"[::-1].split()[::-1]) => olleh dlrow print("hello world =>", *"hello world"[::-1].split()) => dlrow olleh print("hello world =>", *"hello world".split()[::-1]) => world hello
29th Dec 2019, 10:20 PM
rodwynnejones
rodwynnejones - avatar
0
Does it need defining or is it built-in? Saboor Hakimi 🇦🇫
29th Dec 2019, 8:36 PM
Issa