Reverse a string in python


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
def reverse(text):
rev = ''
for i in range(len(text), 0, -1):
rev += text[i-1]
return rev.

<In what way does your code behave incorrectly? Include ALL error messages.>
Please i want to get the understanding of 0, -1 in the range.

<What do you expect to happen instead?>

```python

Replace this line with your code.

<do not remove the three backticks above>

#2

range([start], stop[, step])

start: Starting number of the sequence.
stop: Generate numbers up to, but not including this number.
step: Difference between each number in the sequence.

here 0 means where you want to stop the loop
and -1 means you want to reverse

to make it clear run the following code

text='abcdefghijkl'
for i in range(len(text)-1, 0,-1):
  print i
  print text[i]

#3

Thanks Dear one. I have even made my research to get the understanding.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.