1,reverse是list的内置方法,reversed是个函数
2,reverse是改变原来的list,
def list1(list_num): list_num.reverse()#此处相当于把list_num 逆置了 return list_num print(llist1(['q','w','f']))
reversed 则是变成一个迭代器
# "Let's take LeetCode contest" # 输出: "s'teL ekat edoCteeL tsetnoc" def str01(st): # return ' '.join([ i[::-1] for i in st.split(' ') ] # return ' '.join(st[::-1].split(' ')[::-1]) list1=st[::-1].split(' ') list1.reverse() return ' '.join(list1) # return ' '.join(list(reversed(st[::-1].split(' ')))) if __name__ == '__main__': print(str01("Let's take LeetCode contest"))