Share your repls and programming experiences

← Back to all posts
A reverse function
pole55 (196)

A function that takes a string text and returns that string in reverse.

Commentshotnewtop
ash15khng (678)

@pole55 your reverse function could be changed to:

def reverse(text):
    return text[::-1]

as [::-1] basically tells Python to return a string that is stepped over every 1 letter (which does nothing), but backwards, which reverses the string.

pole55 (196)

@ash15khng, you're right! this is a great option, but I'm only learning the language and trying out different solutions. not only simple and obvious

ash15khng (678)

@pole55 Oh, I was just suggesting another shorter variation to your code, which in most cases is preferable. However your method is more logical so it also works.