Reverse a string in Python

前端 未结 28 2506
南旧
南旧 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 04:54

    Thats my way:

    def reverse_string(string):
        character_list = []
        for char in string:
            character_list.append(char)
        reversed_string = ""
        for char in reversed(character_list):
            reversed_string += char
        return reversed_string
    

提交回复
热议问题