学习笔记(04):Python 面试100讲(基于Python3.x)-如何反转字符串

立即学习:https://edu.csdn.net/course/play/26755/340115?utm_source=blogtoedu

反转字符串:

s1='abcde'

s2=''

for c in s1:

    s2=c+s2

print(s2)

分片反转字符串

设置步长为-1

print(s1[::-1])

发布了7 篇原创文章 · 获赞 0 · 访问量 3279

猜你喜欢

转载自blog.csdn.net/zhaoxiaozheng1987/article/details/104246674