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.
กลับหัวสตริง
return สตริงที่มีตัวอักษรเรียงจากหลังไปหน้า: reverse_string("abc") ให้ผลลัพธ์เป็น "cba"
Python 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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่