娟斌心 发表于 2015-4-22 10:39:13

Python天天美味(8)

方法一,使用[::-1]:

s = 'python'
print s[::-1]
方法二,使用reverse()方法:

l = list(s)
l.reverse()
print ''.join(l)
输出结果:
nohtyp
nohtyp

Python天天美味系列(总)
Python    天天美味(6) - strip lstrip rstrip     Python    天天美味(7) - 连接字符串(join %)
  Python    天天美味(8) - 字符串中的字符倒转
  Python    天天美味(9) - translator
  Python    天天美味(10) - 除法小技巧

...
页: [1]
查看完整版本: Python天天美味(8)