实例:实现输入一句英文后,单词倒序输出,eg:输入“I am a student.”,输出“student. a am I”!
自己面试的时候一道题,这么简单,我竟然不会写,哎!!!算是个教训吧!
def reverse_sentence(sentence): words=sentence.split() words.reverse() new_str=" ".join(words) return new_str s="I am a student." print(reverse_sentence(s))