Reversing a String in Python

This is a good thing to try in prep for an interview or just general skills in python. Even if you are not asked in an interview to do this, it is still a good skill to know how to do it.

Let’s start by defining our function.

By defining a function for this, we can create a system that will more easily reverse any string. Creating a function is also more code friendly because it is more general.

Using the brackets and double parentheses we are able to reverse the string.

Every function needs a return statement to print the answer. We want the reversal variable returned. Now let’s try it out!

It works! Let’s try another example.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store