+ 2

How to reverse this word using string slicing

#[start:stop:step] 'hello'

20th Jun 2017, 11:23 AM
Karthick Raj
Karthick Raj - avatar
8 Answers
+ 4
reverse_word = 'hello'[-1::-1]
20th Jun 2017, 11:41 AM
visph
visph - avatar
+ 5
- using start index -1 target the last index - don't specify the stop index implicitly mean without end (while there's characters) - using -1 at step will decrease index So you get all characters from last (4) to first (0)
20th Jun 2017, 12:25 PM
visph
visph - avatar
+ 5
So, you can upvote, and mark one as 'best answer', as you first do, but immediatly undo ;P
20th Jun 2017, 12:29 PM
visph
visph - avatar
+ 2
ok I will
20th Jun 2017, 12:41 PM
Karthick Raj
Karthick Raj - avatar
+ 1
pls explain this
20th Jun 2017, 12:22 PM
Karthick Raj
Karthick Raj - avatar
+ 1
super explanation
20th Jun 2017, 12:27 PM
Karthick Raj
Karthick Raj - avatar
+ 1
thq so much
20th Jun 2017, 12:27 PM
Karthick Raj
Karthick Raj - avatar
0
a='It is being just fine before I meet you' print(a[::-1])
5th Jan 2021, 5:13 PM
Ujjawal Gupta
Ujjawal Gupta - avatar