スペースで分割
関数 split() はデフォルトで空またはスペース文字を区切り文字として使用します.
alphabet = "a b c d e f"
tstr = alphabet.split()
for c in tstr:
print c
Runtime:
例2:ドメイン名の抽出
Python String split() メソッド
a関数 split() は、以下の例に示すように、文字またはパターンの最大検出数もパラメーターとして取ります:
b
c
d
e
f
alphabet = "a b c d e f"Runtime:
tstr = alphabet.split(" ", 3)
tstr の c の場合:
print c
a
b
c
d e f
例2:ドメイン名の抽出
s = 'exemple.domaine.net'Runtime:
i = s.split('.', 1)
nom_de_domaine = i[1]
print nom_de_domaine
domaine.netReferences:
Python String split() メソッド
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...