文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Python スライス (slice) ====== スライスはシーケンスの一部分を切り取ってコピーを取得する。\\ **テキストシーケンスのスライス**\\ <code> +---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 <- 整数 index -6 -5 -4 -3 -2 -1 <- 負数 index </code> <WRAP group> <WRAP half column> sequence[index]\\ <code python> >>> str = 'Python' >>> str[3] 'h' </code> </WRAP> <WRAP half column> sequence[start:end]\\ <code python> >>> str = 'Python' >>> str[2:4] 'th' </code> </WRAP> </WRAP> <WRAP group> <WRAP half column> sequence[start:]\\ <code python> >>> str = 'Python' >>> str[2:] 'thon' </code> </WRAP> <WRAP half column> sequence[:end]\\ <code python> >>> str = 'Python' >>> str[:4] 'Pyth' </code> </WRAP> </WRAP> <WRAP group> <WRAP half column> sequence[:]\\ <code python> >>> str = 'Python' >>> str[:] 'Python' </code> </WRAP> <WRAP half column> </WRAP> </WRAP> [[https://docs.python.org/ja/3/tutorial/introduction.html#strings|3. 形式ばらない Python の紹介 - 文字列型 (string) - Python ドキュメント]] より\\ ===== シーケンス型 (sequence) ===== list() - リスト\\ tuple() - タプル\\ range() - range オブジェクト\\ ==== バイナリシーケンス型 ==== bytes() - バイトオブジェクト\\ bytearray() - bytearray オブジェクト\\ memoryview() - メモリビュー\\ ==== テキストシーケンス型 ==== str() - テキストシーケンス\\ ===== 参考文献 ===== [[https://docs.python.org/ja/3/library/stdtypes.html#sequence-types-list-tuple-range|組み込み型 - シーケンス型 list, tuple, range - Python ドキュメント]]\\ [[https://docs.python.org/ja/3/library/stdtypes.html#binaryseq|組み込み型 - バイナリシーケンス型 --- bytes, bytearray, memoryview - Python ドキュメント]]\\ [[https://docs.python.org/ja/3/library/stdtypes.html#textseq|組み込み型 - テキストシーケンス型 --- str - Python ドキュメント]]\\ python/slice.txt 最終更新: 2020/03/28 09:38by ともやん