[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?
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
Phantom split() function is build-in and you can call it for Strings ex:- "hey there".split(" ") It will return two strings("hey"," there")
Thank you so much for your help. ~ swim ~
Now it's clear. Thank you so much. Saboor Hakimi 🇦🇫
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
Does it need defining or is it built-in? Saboor Hakimi 🇦🇫