Python字符串反转示例 - 简单易懂的代码实现
以下是一个简单的 Python 例子,它会将输入的字符串反转并输出:
# 接收用户输入的字符串
string = input('请输入一个字符串:')
# 使用切片操作将字符串反转
reversed_string = string[::-1]
# 输出反转后的字符串
print('反转后的字符串为:', reversed_string)
运行该程序,输入一个字符串,例如 'hello world',则输出结果为:
请输入一个字符串:hello world
反转后的字符串为: dlrow olleh
原文地址: https://www.cveoy.top/t/topic/nCVr 著作权归作者所有。请勿转载和采集!