首页 > 游戏数码 > 电脑 > python中字符串如何反转?

python中字符串如何反转?

   来源:秒知站    阅读: 1.58W 次
字号:

用手机扫描二维码 在手机上继续观看

手机查看

怎样在 python 中将字符串“hello word”反转打印呢?介绍几种方法供大家参考。

操作方法

(01)切片法

(02)>>> 'hello world'[::-1]'dlrow olleh'

python中字符串如何反转?

(03)切片的扩展语法。步长为-1, 即字符串的翻转

方法/步骤2

(01)for循环输出

(02)string ='hello world'print ''(string[i] for i in range(len(string)-1, -1, -1))dlrow olleh

python中字符串如何反转? 第2张

电脑网络
IT技术
互联网
电脑
摄影
手机
游戏