怎样在 python 中将字符串“hello word”反转打印呢?介绍几种方法供大家参考。
方法/步骤
1
切片法
2
>>> 'hello world'[::-1]'dlrow olleh'
3
切片的扩展语法。步长为-1, 即字符串的翻转
方法/步骤2
1
for循环输出
2
string ='hello world'print ''.join(string[i] for i in range(len(string)-1, -1, -1)) dlrow olleh
上一篇:电子表格中如何返回字符串的位数