字符串

字符串反转

1、while循环

str01 = "hello"

i=len(str01)-1
s=''
while i>=0:
    s+=str01[i]
    i-=1
print(s)

2、字符串切片


str01 = "hello"
print(str01[::-1])

3、列表函数

str01 = "hello"

str02=list(str01)
str02.reverse()
print(''.join(str02))

 

 

posted @ 2022-06-23 20:15  爱coding的果妈  阅读(12)  评论(0)    收藏  举报