In python, how would you swap the first and last parts of a string but leave the middle character in the same place? For example, if I have ABCDE, then the result would be DECAB.
def swap(str1):
return str1[-1]+str1[1:-1]+str1[:1]
print(swap("Hello"))
With this, I am only able to swap the first and last letter of the string. So the result for 'Hello' is 'oellH'.