-2

Hello everyone im trying to reverse a string in python but i cant get it to work. I tried using reversed but it didnt work. I found the replacment for it but it i cant get it to work properly. Explenanation and help would be appriciated.

code

word="cba"
word[::1]
print (word)
Invader
  • 11
  • 2

1 Answers1

0

Not word[::1], but word[::-1]: it's a slice with step -1. But I can't understand your problems with reversed - it's even more simple: reversed(word).

Eugene Primako
  • 2,767
  • 9
  • 26
  • 35
  • 1
    `reversed` returns a generator so you would need `''.join(reversed(word))` to get the same result as `word[::-1]` – AChampion Jan 05 '16 at 14:31
  • 1
    Just changing the 1 to -1 in the OP's code [won't change what gets printed](http://ideone.com/twE7dc). – Kevin Jan 05 '16 at 14:34