Python 字符串翻转
Python 字符串翻转的例子
给定一个字符串,然后将其翻转,逆序输出。
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
str='Lidihuo'
print(str[::-1])
执行以上代码输出结果为:
使用 reversed()
# Filename : example.py
# DateTime : 2020-07-20
# author by : www.lidihuo.com
str='Lidihuo'
print(''.join(reversed(str)))
执行以上代码输出结果为: