【一题多解】Python 字符串逆序

https://blog.csdn.net/seetheworld518/article/details/46756639
https://blog.csdn.net/together_cz/article/details/76222558

1. 使用索引

>> strA = 'abcdefg'
>> strA[::-1]
'gfedcba'

2. 使用 list 的 reverse 方法

>> l = [c for c in strA]
>> l.reverse()
>> ''.join(l)
'gfedcba'

3. 使用 python 原生函数:reversed

>> ''.join(c for c in reversed(strA))
'gfedcba'

猜你喜欢

转载自blog.csdn.net/lanchunhui/article/details/81058012