👩💻
言語処理100本ノック 2020 (Rev 2) 第1章: 準備運動 00. 文字列の逆順
問題
00. 文字列の逆順
文字列”stressed”の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.
solution00.py
# Sequence types (list, tuple, string, range) support slicing.
# Therefore, you can sort in reverse order by setting text[::-1] in the slice operation.
text = "stressed"
print(text[::-1])
# You can also use reversed() method.
print(''.join(reversed(text)))
output
desserts
desserts
この問題では、文字列を逆順に並び替えます。
Discussion