文字列(主にstrクラス)の機能(Python覚書 ver3.1/WindowsXP)

# 空白文字で区切ってlistに変換
print( "abc def ghi".split() )
  #=> ['abc,', 'def,', 'ghi']

# 引数でカンマを指定して、カンマ区切りでlistに変換
print( "jkl,mno,pqr".split(",") )
  #=> ['jkl', 'mno', 'pqr']

# 生成する要素の数を制限できる
print( "a,b,c,d,e,f,g".split(",", 3) )
  #=> ['a', 'b', 'c', 'd,e,f,g']

# splitlinesを使って改行で区切る
print( "a\r\nb\rc\n".splitlines() )
  #=> ['a', 'b', 'c']

# rsplitは、だいたいsplitと同じ振る舞い
print( "a b c d".rsplit() )
  #=> ['a', 'b', 'c', 'd']
# 引数を2つ使用した場合に、右側からsplitしてることが分かる
print( "a b c d e f g".rsplit(" ", 3) )
  #=> ['a b c d', 'e', 'f', 'g']

# joinを使用して、文字列をカンマで切ってみる
print( ",".join("str") )
  #=> s,t,r

# partitionは3つのtupleを返す
print( "test=10".partition("=") )
  #=> ('test', '=', '10')
# セパレータがない場合は、1つめの要素に全文字列が入る
print( "test=10".partition(",") )
  #=> ('test=10', '', '')

# rpartitionはpartitionとだいたい同じ動き
print( "test=10".rpartition("=") )
  #=> ('test', '=', '10')
# セパレータがない場合は、3つ目の要素に文字列が入る
print( "test=10".rpartition(",") )
  #=> ('', '', 'test=10')