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

前端 未结 30 2593
南旧
南旧 2020-11-30 19:44

I came across a strange Codecademy exercise that required a function that would take a string as input and return it in reverse order. The only problem was you could not use

30条回答
  •  悲哀的现实
    2020-11-30 19:57

    All I did to achieve a reverse string is use the xrange function with the length of the string in a for loop and step back per the following:

    myString = "ABC"
    
    for index in xrange(len(myString),-1):
        print index
    

    My output is "CBA"

提交回复
热议问题