Python: My function returns "None" after it does what I want it to [duplicate]

Solution 1:

function return None by default, so you should return backwards explicitly

also, you can use a pythonic way to solve the problem:

letters[::-1]

Solution 2:

You can use a return statement to exit the function returning a value. If the function gets to the end without reaching a return statement, it will return None by default

def add1(x):
   return x+1

def returnsNone():
   pass

print(add1(2))
print(returnsNone())

Solution 3:

Every function returns something in Python. If you don't explicitly return a value, Python has your function return None.

Your function doesn't actually return anything because print prints to stdout, while return actually returns a value. They may look the same in the REPL, but they're completely different.

So to fix your problem, return a value:

return backwards