Python: Exemple de concaténation d’une liste

Author:

 list, list
{filelink=15883}

# Définition d'une liste
a = [1, 2, 3]
print a # [1, 2, 3]

# Concaténation avec une liste vide
maList= a  + []
print maList #[1, 2, 3]

# Concaténation avec une liste non prédéfinie
maList= a + [4, 5, 6]
print maList #[1, 2, 3, 4, 5, 6]

# Concaténation avec l'opérateur '+'
maList+=[7, 8, 9]
print maList #[1, 2, 3, 4, 5, 6, 7, 8, 9]

Livres Sur ce Sujet

[amazon_image id=”2212134347″ link=”true” target=”_blank” size=”medium” ]Apprendre à programmer avec Python 3[/amazon_image] [amazon_image id=”B005J2L260″ link=”true” target=”_blank” size=”medium” ]Apprenez à programmer en Python[/amazon_image] [amazon_image id=”2100508830″ link=”true” target=”_blank” size=”medium” ]Python : Petit guide à l’usage du développeur agile[/amazon_image] [amazon_image id=”2212127081″ link=”true” target=”_blank” size=”medium” ]Apprendre à programmer avec Python 3 : Avec plus de 50 pages de corigés d’exercices ![/amazon_image]

Leave a Reply

Your email address will not be published. Required fields are marked *