avatar Bite 8. Rotate string characters

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!

Login and get coding
go back Beginner level
Bitecoin 2X

1595 out of 1649 users completed this Bite.
Will you be Pythonista #1596 to crack this Bite?
Resolution time: ~33 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.57 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.
We use Python 3.8