Python_字符串反转

变成列表(可变)操作后,再变成字符串(不可变)

"""
    将英文语句进行反转
    How are you  ->  you are How
"""
string = "How are you"
#
string_list = string.split(" ")
string_list = string_list[::-1]
rev_string = " ".join(string_list)
print(rev_string)

运行结果

you are How
发布了56 篇原创文章 · 获赞 0 · 访问量 901

猜你喜欢

转载自blog.csdn.net/Rookie_Max/article/details/104044206