反转字符串的顺序 [英] invert the order of a string

查看:59
本文介绍了反转字符串的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

s = list(''some_random_string'')

print s

s.reverse()

print s

s =''''。join(s)

print s


肯定有更好的方法可以做到这一点,对吧? br />

s = list(''some_random_string'')
print s
s.reverse()
print s
s = ''''.join(s)
print s

Surely there''s a better way to do this, right?

推荐答案

2006年2月13日星期一18:51:11 +0000在comp.lang.python,rtilley

< ; RT ***** @ vt.edu>写道:
On Mon, 13 Feb 2006 18:51:11 +0000 in comp.lang.python, rtilley
<rt*****@vt.edu> wrote:
s = list(''some_random_string'')
print s
s.reverse()
print s
s =''''.join(s)
打印s

肯定有更好的方法来做到这一点,对吗?
s = list(''some_random_string'')
print s
s.reverse()
print s
s = ''''.join(s)
print s

Surely there''s a better way to do this, right?




怎么样


s ="一些随机字符串"

print s

s = s [:: - 1]

打印s


HTH,

- =戴夫

- =戴夫


-

改变是不可避免的,进步不是。



How about

s = "some random string"
print s
s = s[::-1]
print s

HTH,
-=Dave
-=Dave

--
Change is inevitable, progress is not.


Dave Hansen写道:
Dave Hansen wrote:
怎么样

s ="一些随机字符串>
打印s
s = s [:: - 1]
print s
How about

s = "some random string"
print s
s = s[::-1]
print s




看起来像Perl,但它确实有效。让我想知道字符串

模块没有反转或反转功能?



That looks like Perl, but it works. Makes me wonder with the string
module doesn''t have a reverse or invert function?


rtilley< rt * ****@vt.edu>写道:
rtilley <rt*****@vt.edu> writes:
s = list(''some_random_string'')
print s
s.reverse()
print s
s =''' '.join(s)
打印s

肯定有更好的方法来做到这一点,对吗?
s = list(''some_random_string'')
print s
s.reverse()
print s
s = ''''.join(s)
print s

Surely there''s a better way to do this, right?




In Python 2.4,只是说

s = reverse(''some_random_string'')



In Python 2.4, just say
s = reversed(''some_random_string'')


这篇关于反转字符串的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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