Reverse: works but adds "None" after my revsered string. Why?


Hi guys, I'm new to Python and I'd like some answers to get a better understanding of how python works.

In the Reverse exercice (see link above) you have to create a function that takes a string and pints it backwards. My code does so but a "None" gets printed after the last letter of the reversed string is printed.

My output for the code below is : !nohtyPNone

Why does it do that and how to solve it ?

Thanks in advance

from __future__ import print_function

def reverse(text):
    for y in range(-1,(-1*len(text))-1,-1):
        print (text[y],end='')



Is the "None" on the next line or combined with the string printed?


Yes exactly like this
Output: !nohtyPNone


This does not look like a solution that would be expected since it is Python 3 and the lesson is Python 2. Did you copy this from another topic?


no I created it but I found the solution to print on the same line from stack overflow


The end='' argument overrides the linebreak. This permits multiline statements to continue printing on the same line.

None is the console response to a return from a function. It can be ignored.


Ok so I should consider the exercise completed although CodeAcademy doesn't think it is. I can always try to come up with another solution until Python considers it completed or copy paste someone else's solution.

Anyway thanks a lot for your answers, much appreciated :slight_smile:


It's a simple enough practice problem that you should be able to come up with a number of working solutions without copying. Can be done with iteration or slicing.

Concerning your approach above, did you try,



using the reverse command is not allowed for the exercise, otherwise it'd be too easy. I'll come up with another solution. Thanks again


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