Python的字符串反转方法

PYTHON2010-11-02 09:56

假设有字符串"s",如下方法进行反转(下面是在iPython中的输入输出):

In [1]: s='123456789'
In [2]: s
Out[2]: '123456789'

In [3]: s[::-1]
Out[3]: '987654321'

In [4]: reduce(lambda x,y:y+x,s)
Out[4]: '987654321'

In [5]: x=list(s); x.reverse(); "".join(x)
Out[5]: '987654321'


原文链接: http://blog.jtwo.me/the-method-to-reversal-python's-string