Reverse a string in Python

前端 未结 28 2559
南旧
南旧 2020-11-21 04:41

There is no built in reverse function for Python\'s str object. What is the best way of implementing this method?

If supplying a very conci

28条回答
  •  忘了有多久
    2020-11-21 05:01

    This is simple and meaningful reverse function, easy to understand and code

    def reverse_sentence(text):
        words = text.split(" ")
        reverse =""
        for word in reversed(words):
            reverse += word+ " "
        return reverse
    

提交回复
热议问题