0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

言語処理100本ノック 2015 :00

Last updated at Posted at 2022-08-21

第1章 準備運動

テキストや文字列を扱う題材に取り組みながら,プログラミング言語のやや高度なトピックを復習します.


  1. 文字列の逆順
    文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.

00. 文字列の逆順

文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.

コード

text = "stressed"
result = text[::-1]
print(result)

結果

desserts

反省点

  • Pythonのスライス処理で反転する方法がわからなかった
  • reverseメソッドとreversed関数の違いがわかなかった
    -> reverseメソッド:元のリストの要素を入れ替える
    -> reversed関数:新しいリストで入れ替える、イテレータを戻すので注意

参照

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?