欢迎来到趣知常识网!
>
怎样在 python 中将字符串“hello word”反转打印呢?介绍几种方法供大家参考。
(01)切片法
(02)>>> 'hello world'[::-1]'dlrow olleh'
(03)切片的扩展语法。步长为-1, 即字符串的翻转
(01)for循环输出
(02)string ='hello world'print ''(string[i] for i in range(len(string)-1, -1, -1))dlrow olleh
图文推荐
相关文章