我如何将其转换为python? [英] How do I convert this to python?

查看:72
本文介绍了我如何将其转换为python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string reverse(string word){
string temp = "";
if(word.length() > 1){
temp = word.substr(word.length()-1, word.length());
temp += reverse(word.substr(0, word.length()-1));
}
else
return word;
return temp;





到目前为止我已经有了...





so far I've got...

def reverse(word):
temp = ''
if word.len() > 1:

推荐答案

只需一行代码即可反转字符串蟒蛇。阅读文档 [ ^ ]

Just a one line code to reverse the string in python. Read the documentation[^]
s[::-1]
'dcba'
# where s was 'abcd' and then it is voila



或者不使用它:


Or without using it:

def reverse(test):
    n = len(test)
    x=""
    for i in range(n-1,-1,-1):
        x += test[i]
    return x



虽然您可以在此主题 [ ^ ]。



-KR


Though you can find certain help on this thread[^].

-KR


这篇关于我如何将其转换为python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆