Latest web development tutorials

python3スプリット()メソッド

python3文字列 python3文字列


説明

、唯一のサブストリングを分離NUMパラメータnumの値が指定されている場合、文字列のセクションの区切り文字を指定することで、分割()

文法

スプリット()メソッドの構文:

str.split(str="", num=string.count(str)).

パラメータ

  • STR - セパレータ、デフォルトのスペース。
  • NUM - 分割数。

戻り値

分割後の文字列のリストを返します。

次の例では、使用するスプリット()関数を示しています。

#!/usr/bin/python3

str = "this is string example....wow!!!"
print (str.split( ))
print (str.split('i',1))
print (str.split('w'))

次のように上記の出力結果の例は次のとおりです。

['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']

python3文字列 python3文字列