fork download
  1. def reverse(strInput):
  2. ''' reverses the string held in str
  3. '''
  4. strInput=list(str(strInput))
  5.  
  6. for i in range(0, len(strInput)//2):
  7. strInput[i], strInput[len(strInput)-1-i] = strInput[len(strInput)-1-i], strInput[i]
  8.  
  9. return "".join(strInput)
  10.  
  11. if __name__ == '__main__':
  12. tests = (["abc", "abcd", "with spaces", " with spaces",
  13. "with spaces ", "abcdefghijklmnopqrstuvwxyz"])
  14. for t in tests:
  15. print("The reverse of [{0}] is [{1}]."
  16. .format(t, str(reverse(t))))
  17.  
Success #stdin #stdout 0.01s 28376KB
stdin
Standard input is empty
stdout
The reverse of [abc] is [cba].
The reverse of [abcd] is [dcba].
The reverse of [with spaces] is [secaps htiw].
The reverse of [ with spaces] is [secaps htiw ].
The reverse of [with spaces ] is [ secaps htiw].
The reverse of [abcdefghijklmnopqrstuvwxyz] is [zyxwvutsrqponmlkjihgfedcba].