Split par espace
La fonction split() prend par défaut le caractère vide ou espace comme délimiteur.
alphabet = "a b c d e f"
tstr = alphabet.split()
for c in tstr:
print c
Exécution:
Exemple 2: extraction du nom de domaine
Python String split() Method
aLa fonction split() prend aussi comme paramètre le nombre maximum de détection d'un caractère ou un motif comme le montre l'exemple ci-dessous:
b
c
d
e
f
alphabet = "a b c d e f"Exécution:
tstr = alphabet.split(" ", 3)
for c in tstr:
print c
a
b
c
d e f
Exemple 2: extraction du nom de domaine
s = 'exemple.domaine.net'Exécution:
i = s.split('.', 1)
nom_de_domaine = i[1]
print nom_de_domaine
domaine.netRéférences:
Python String split() Method
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...