Skip to content · ⁨דלג לתוכן⁩

Reverse a string · ⁨הפוך מחרוזת⁩

English

Reverse a string

Return the string with its characters back-to-front: reverse_string("abc") gives "cba".

Python slicing has a neat trick: s[::-1] walks the string with a step of -1, from the end to the start. You can also build the answer with a loop if you prefer.

עברית

הפוך מילה

החזר את המחרגת עם התווים הפוכים: reverse_string("abc") נותן "cba".

לפיצ'ון חתירה (slicing) יש טריק נחמד: s[::-1] עובר על המילה עם צעד של -1, מהסוף להתחלה. ניתן גם לבנות את התשובה עם לולאה אם מעדיפים.

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP