Python string with character exchange

Reto reto at labrat.space
Sun Jul 14 14:26:43 EDT 2019


On Sun, Jul 14, 2019 at 12:20:56PM -0400, Matt Zand wrote:
> Given a string, return a new string where the first and last chars have
> been exchanged.

This sounds awfully like a homework question.
What did you try?
What concepts are you missing?

Did you already look into slicing / getting element from a list?
That will be what you need in the end.

You can easily get a character from a string like this

```
a = "some random string"
print(a[0])
```

strings are immutable in python, meaning you will need to create a new string.



More information about the Python-list mailing list