Given a string, and we have to swap all characters using python program.
In this article, we would learn how to return a string with swapped characters? This can be solved by either introducing a variable N or by just simply considering the length of the string itself.
Question:
If you are provided with a string, return a new string such that the first and the last characters have been exchanged. Also, you should consider the following cases:
Example:
swap_string ('love') = 'eovl'
swap_string ('g') = 'g'
swap_string ('ab') = 'ba'
Code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer