Show three ways to reverse a Python string and compare them.
There are three standard ways to reverse a string in Python, and all three of them give you exactly the same result.
text = 'python'
print(text[::-1]) # slicing with a negative step
print(''.join(reversed(text))) # reversed() plus join
print(''.join(list(reversed(text)))) # explicit list
print(list(text)) # ['p', 'y', 't', 'h', 'o', 'n']
print(list(reversed(text))) # ['n', 'o', 'h', 't', 'y', 'p']
The slicing version is the one to give first. It is a single character, it reads clearly once you know the idiom, and it is the fastest of the three because the work happens inside the interpreter.
The reversed() version is the most explicit about what is happening. reversed() works with any sequence and it gives you an iterator, so the join call is what turns that iterator back into a string. The list version does the same job with one extra step, and it is occasionally useful when you want to look at the intermediate list.
Why join is needed at all is worth explaining, because it trips people up. reversed() gives you an iterator of characters and not a string, and strings do not have a reverse method, so there is no text.reverse() in Python. The join call is the standard way of putting an iterable of characters back together into one string.
One more thing is worth saying in an interview. The strip() family of methods gives you a new string rather than changing the string in place, and every reversing approach behaves in the same way. If you need to keep the original, put the result into a new name.