Editor

Reverse a String

Beginner · Write the code · from Python For Loops: Iterate Over Anything with Examples

From the lesson: Python For Loops: Iterate Over Anything with Examples

Imagine you're a teacher with 30 students. You need to print a report card for each one. Would you write 30 separate print statements? Of course not. You'd tell the computer: "for each student, print their report card." That's exactly what a for loop does.

Read the lesson

Use a for loop to reverse the string "Python" by building a new string character by character. Do NOT use slicing ([::-1]) or the reversed() function.

Expected output:

nohtyP
original = "Python"
reversed_str = ""
# Use a for loop to build the reversed string
print(reversed_str)

More For Loops exercises

All Python exercises · 50 practice problems · Control Flow quiz