I am working on a function to reverse a string and when I run it I get two errors, one at tot -= i
showing TypeError: unsupported operand type(s) for -=: 'str' and 'str'
, and at print(reverse(thestr))
.
However, if I put the +
in tot += i
, it works. How can I solve this, as for my understanding when using -
it will go in reverse?
def reverse(c):
tot = ''
for i in c:
tot -= i
return tot
thestr = 'This is a Test'
print(reverse(thestr))