+ 2

How to reverse a string with preserving the spaces using python

21st Nov 2019, 12:20 AM
R Vijay Anand
R Vijay Anand - avatar
4 Antworten
+ 1
Just: your_string = your_string[::-1] (Or, if it's the *position* of the spaces which you want to preserve, what Błack Jesus❕ said.)
21st Nov 2019, 8:58 AM
HonFu
HonFu - avatar
- 1
Can you write a python program and give?
21st Nov 2019, 12:42 AM
R Vijay Anand
R Vijay Anand - avatar
- 1
A simple way to do it: new_string = ''.join(list(old_string)[::-1]) I hope that is good enough for you!
21st Nov 2019, 8:28 AM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar