Quick code challenge: Reverse a string in python

·

0 min read

I was procrastinating on twitter the other day and I saw this tweet from Florin Pop. I decided to get in on the fun but use python instead, as part of that. Here is how to reverse a string in python.

carbon.png

The code takes in a word, then uses a while loop to reverse the word by saving the last letter into a string and then the second last word and so on until the whole string is complete. The len() function lets us know the length of the word which the code uses to set the exact number of loops needed to reverse the entire string.