+91 81900 98289

Reverse a String

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.

Example 1: Start here

topic itself is still Python.

topic = "Python" # text print(topic[::-1])

Example 2: 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)))

Example 3: Reverse in place

reverse changes the list itself.

skills = ["Python", "SQL", "Git"] # a list; the values stay in this order skills.reverse() print(skills)

Example 4: Reverse a word

A slice with step -1 walks the text backward.

print("Python"[::-1]) # print writes this; the quotes are not shown
topic itself is still Python.
Call Now 81900 98289