python實現輸入一段英文單詞后,倒敘輸出


實例:實現輸入一句英文后,單詞倒序輸出,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))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM