字符串反转/列表元素反转

列表反转

lst=[1,2,3,4]
new_lst=[]
for x in reversed(lst):
    new_lst.append(x)
print(new_lst)

print(lst[::-1])

字符串反转

str='Apollo'
new_str=''
for x in reversed(str):
    new_str+=x
print(new_str)

print(str[::-1])

猜你喜欢

转载自www.cnblogs.com/apollo1616/p/9776518.html