python:slice

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

python:slice [2020/03/28 09:08] – 作成 ともやんpython:slice [2020/03/28 09:38] (現在) ともやん
行 1: 行 1:
-====== Python スライス ======+====== Python スライス (slice) ====== 
 +スライスはシーケンスの一部分を切り取ってコピーを取得する。\\ 
 +**テキストシーケンスのスライス**\\ 
 +<code> 
 + +---+---+---+---+---+---+ 
 + | P | y | t | h | o | n | 
 + +---+---+---+---+---+---+ 
 +              <-  整数 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() - リスト\\ list() - リスト\\
 tuple() - タプル\\ tuple() - タプル\\
  • python/slice.1585354136.txt.gz
  • 最終更新: 2020/03/28 09:08
  • by ともやん