+ 4

String 1 to 2

Please how can I convert string “str” to “str1” Please note, I do not Inted to print It but assign It to a variable. Str = “this is worderful” I’ll like to have str1 = “this! Is! Wonderful!”

26th Aug 2019, 1:26 PM
Kayode Adetayo
Kayode Adetayo - avatar
5 RĂ©ponses
+ 15
Like so: str ="this is worderful" str1 = "! ".join(str.split()) + '!' print(str1)
26th Aug 2019, 1:39 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 8
it is also possible to use a for loop: txt = 'this is wonderful' lst = txt.split(' ') txt1 = '' for i in lst: txt1 += i + '! ' print(txt1)
26th Aug 2019, 2:54 PM
Lothar
Lothar - avatar
+ 1
str="this is wonderfull" str1="!".join(str.split(" ")) print(str1 )
26th Aug 2019, 7:38 PM
Muhammad Mehran Bin Azam
Muhammad Mehran Bin Azam - avatar
+ 1
new_str = ' '.join(map(lambda x: f'{x}!', str.split()))
27th Aug 2019, 9:30 AM
alex_shchegretsov
alex_shchegretsov - avatar
26th Aug 2019, 2:32 PM
Kayode Adetayo
Kayode Adetayo - avatar