A very popular question is how to reverse a C-Style string. The C-Style string by definition is a string that is terminated by a null(‘\0’). Using C(or maybe C++), it is possible to use pointers to manipulate the string to reverse its contents in-place.
If somebody asks the question, “How do you reverse a C-style string in Python?”, what would some of the possible answers be?
Thanks
If you need to “reverse a C-style string in Python”, I think the end result must also be a c-style string.
That is how I would understand the question, but the above answers do not support this.
See the interactive session below:
Also note, Python strings are immutable. This means that they can never be changed. You can make new strings that are assigned to the same variable name, but the in-memory image for a given strings will never change. Thus, the notion of “reverse a string in place” can not happen in Python.
Hope this helps. If so, please up-vote and accept the answer. Thanks. 🙂