+ 1
How to write a python code that collects user input(which is a word) and then outputs it backward
WRITING WORD BACKWARDS
5 Answers
+ 3
word = input()
rev_word = word[::-1]
print(rev_word)
# For example I input "Hello" :
Output:
>> olleH
+ 5
word = word[ : : -1]
Parameters:
word [ start_index : end_index : steps ]
The start_index and end_index is not specified so by default it is 0 and end of the string respectively. Then -1 means 1 step backward (negative).
That is also equivalent to this:
---> word = word[ 0 : len(word) : -1 ]
Other method:
---> word[::-1] = word
# This reverses the string without changing the memory address.
+ 2
So write like an example code please
+ 1
Thanks alot i really appreciate
+ 1
If you want to do that with code instead of slicing.....you can do that like this-
s = input ()
rev = ''
for i in range(len(s)):
rev +=s[-(i+1)]
print(rev)