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".
تتمتع عملية تقطيع النصوص في بايثون بحيل ذكية: يمشي 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 بأحرفها مقلوبة. شريحة s[::-1] تفعل ذلك في خطوة واحدة.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.