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?
7 odpowiedzi
+ 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
+ 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")
+ 1
Thank you so much for your help. ~ swim ~
+ 1
Now it's clear. Thank you so much. Saboor Hakimi 🇦🇫
+ 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
0
Does it need defining or is it built-in? Saboor Hakimi 🇦🇫