This Reverse a String lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
A slice with a step of -1 reverses text. reversed walks the characters backwards, and join builds the string.
Neither call changes the original string.
Start here
topic itself is still Python.
topic = "Python" # text
print(topic[::-1])
Reverse a list
reversed does not change the original list.
skills = ["Python", "SQL", "Git"] # a list; the values stay in this order
print(list(reversed(skills)))
Reverse in place
reverse changes the list itself.
skills = ["Python", "SQL", "Git"] # a list; the values stay in this order
skills.reverse()
print(skills)
Reverse a word
A slice with step -1 walks the text backward.
print("Python"[::-1]) # print writes this; the quotes are not shown
