+ 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!”
5 ответов
+ 15
Like so:
str ="this is worderful"
str1 = "! ".join(str.split()) + '!'
print(str1)
+ 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)
+ 1
str="this is wonderfull"
str1="!".join(str.split(" "))
print(str1 )
+ 1
new_str = ' '.join(map(lambda x: f'{x}!', str.split()))
0
Михаил Горчанюк thanks a lot.