0

Following is the easiest way of reversing a string in python:

    string = 'SHWETA'
    print(string[: : -1])

I just wanted to know if this code is executing in-place or taking any extra space.

1
  • 6
    This is not in-place, since strings are immutable and return a new object whenever modified Commented Jun 19, 2019 at 12:41

1 Answer 1

1

Strings in Python are immutable which means you cannot apply any change to an existing string. Any modifications you apply to a string will return a new string object reflecting those changes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.