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" を与えます。

Pythonのスライシングには便利な技があります: s[::-1] はストリングを -1 のステップで、末尾から先頭へたどります。必要であればループを使って作成することもできます。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP