<Python> 文字列のスライス。

文字列CharのスライスSlice
スライスSliceで飛び数Stepが選択できることを知った。
しかも、逆にも飛べる。

str[from:to:step]の書式でいけるらしい。
step-1にすると、逆に戻る。

In [1]: str = '12345'

In [2]: str[0]
Out[2]: '1'

In [3]: str[-1]
Out[3]: '5'

In [4]: str[-1::-1]
Out[4]: '54321'

In [5]: str[-1:0:-1]
Out[5]: '5432'

In [6]: str[-1:1:-1]
Out[6]: '543'

In [7]: str[-1:-1:-1]
Out[7]: ''

In [8]: str[-1:-5:-1]
Out[8]: '5432'

In [9]: str[-1:-6:-1]
Out[9]: '54321'

いいねー。

stackoverflow
list - Explain Python's slice notation - Stack Overflow

過去記事。
nekoyukimmm.hatenablog.com

マニュアル。
3. 形式ばらない Python の紹介 — Python 3.4.3 ドキュメント

4. 組み込み型 — Python 3.4.3 ドキュメント

マニュアル。英語。3.5版。
4. Built-in Types — Python 3.5.0 documentation