-1

I want to know how to reverse a string in python without creating a new one.

I can't seem to get it.

Khizar Khan
  • 1
  • 1
  • 1

1 Answers1

1

Python strings are immutable, which means you can't really change it. There's no way you could reverse it in-place.

Obviously, you could reassign the same variable to it, but this is not an in-place change as you asked for:

str = 'reverse'
str = str[::-1]
Vitor Falcão
  • 1,007
  • 1
  • 7
  • 18