小编Zee*_*ran的帖子

如何在python中将字符串向右移?

我尝试将一个字符串向右移动

  • 最后一个值应该是第一个,其余值如下
  • s= "I Me You" 应该回来 "You I Me"

我尝试了以下代码,但它不起作用请帮助我..

sr= "I Me You"
def shift_right(sr):
    L=sr.split()
    new_list=L[-1]

    new_list= new_list.append(1,L[:0])
    return (new_list)

print(shift_right(sr)
print (shift_reverse(sr))
Run Code Online (Sandbox Code Playgroud)

python

8
推荐指数
3
解决办法
8735
查看次数

如何将字符串向右移动并在python中将其反转?

将单词向右移动然后将其反转.

您应该向右移动一个单词并将其反转然后返回如下:

>>> shift_reverse('Introduction to Computer Programming')
gnimmargorP noitcudortnI ot retupmoC
Run Code Online (Sandbox Code Playgroud)

我尝试使用这种方法找到上面的答案但它似乎没有工作请帮助:(

s= "I Me You"
def shift_reverse(s):
    l= s.split()
    new_str= ' '.join(l[-1:] + l[:-1])
    new_str = new_str[::-1]
    return (new_str)

print (shift_reverse(s))
Run Code Online (Sandbox Code Playgroud)

但我得到的印刷品是

[evaluate untitled-3.py]
eM I uoY
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
2794
查看次数

标签 统计

python ×2