Rotating strings in Python

后端 未结 5 713
面向向阳花
面向向阳花 2020-12-03 22:51

I was trying to make the string HELLO to OHELL in Python. But couldn\'t get any way to rotate it without working with loops. How to code for it in

5条回答
  •  盖世英雄少女心
    2020-12-03 23:04

    Here is a simple way of looking at it...

    s = 'HELLO'
    for r in range(5):
        print(s[r:] + s[:r])
    
    
    HELLO
    ELLOH
    LLOHE
    LOHEL
    OHELL
    

提交回复
热议问题