Home >Backend Development >Python Tutorial >Python 字符串中的字符倒转

Python 字符串中的字符倒转

WBOY
WBOYOriginal
2016-06-16 08:47:351287browse

方法一,使用[::-1]:
s = 'python'
print s[::-1]

方法二,使用reverse()方法:
l = list(s)
l.reverse()
print ''.join(l)
输出结果:
nohtyp
nohtyp

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn