Pybites Logo

Rotate string characters

Level: Beginner (score: 2)

Write a function that rotates characters in a string in either direction:

- If n is positive, move n characters from beginning to end, e.g.: rotate('hello', 2) would return "llohe".

- If n is negative, move the last n characters to the start of the string, e.g.: rotate('hello', -2) would return "lohel".

Take a look at the tests for more details. Have fun!