TUTORIALProgrammingFETCHED

Python 字符串翻转

Python 字符串翻转 Python3 实例 给定一个字符串,然后将其翻转,逆序输出。 实例 1:使用字符串切片 [mycode3 type='python'] str='Runoob' print(str[::-1]) [/mycode3] 执行以上代码输出结果为: boonuR 实例 2:使用 reversed() [mycode3 type='..

Updated 7/16/2026

Tutorial detail pages default to noindex.

Python 字符串翻转

Document 对象参考手册 Python3 实例

给定一个字符串,然后将其翻转,逆序输出。

实例 1:使用字符串切片

str='Runoob' print(str[::-1])

执行以上代码输出结果为:

boonuR

实例 2:使用 reversed()

str='Runoob' print(''.join(reversed(str)))

执行以上代码输出结果为:

boonuR

Document 对象参考手册 Python3 实例