====== Python スライス (slice) ====== スライスはシーケンスの一部分を切り取ってコピーを取得する。\\ **テキストシーケンスのスライス**\\ +---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 <- 整数 index -6 -5 -4 -3 -2 -1 <- 負数 index sequence[index]\\ >>> str = 'Python' >>> str[3] 'h' sequence[start:end]\\ >>> str = 'Python' >>> str[2:4] 'th' sequence[start:]\\ >>> str = 'Python' >>> str[2:] 'thon' sequence[:end]\\ >>> str = 'Python' >>> str[:4] 'Pyth' sequence[:]\\ >>> str = 'Python' >>> str[:] 'Python' [[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 ドキュメント]]\\