TUTORIAL编程语言与算法FETCHED
Python 字符串翻转
Python 字符串翻转 Python3 实例 给定一个字符串,然后将其翻转,逆序输出。 实例 1:使用字符串切片 [mycode3 type='python'] str='Runoob' print(str[::-1]) [/mycode3] 执行以上代码输出结果为: boonuR 实例 2:使用 reversed() [mycode3 type='..
更新于 2026/7/16
教程详情页默认 noindex。
Python 字符串翻转
给定一个字符串,然后将其翻转,逆序输出。
实例 1:使用字符串切片
str='Runoob'
print(str[::-1])
执行以上代码输出结果为:
boonuR
实例 2:使用 reversed()
str='Runoob'
print(''.join(reversed(str)))
执行以上代码输出结果为:
boonuR
Python3 实例