Reverse a string · הפוך מחרוזת
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, מהסוף להתחלה. ניתן גם לבנות את התשובה עם לולאה אם מעדיפים.
Write reverse_string(s) that returns s with its characters in reverse order. A slice s[::-1] does it in one step. · כתוב פונקציה reverse_string(s) שמחזירה את s עם האותיות בסדר הפוך. פרוטה (slice) s[::-1] עושה זאת בשלב אחד.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.