Reverse a string in Python

前端 未结 28 2575
南旧
南旧 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:13

    Reverse a string in python without using reversed() or [::-1]

    def reverse(test):
        n = len(test)
        x=""
        for i in range(n-1,-1,-1):
            x += test[i]
        return x
    

提交回复
热议问题