Modification de la Valeur par Indice
Dans ce chapitre, nous allons apprendre à modifier la valeur d'un élément d'une liste en utilisant son indice en Python. Pour modifier un élément spécifique, accédez à la liste à l'indice souhaité et attribuez-lui une nouvelle valeur. Par exemple :
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Change the second element inventory[1] = "parrot" # inventory is now ["cat", "parrot", "chicken", "monkey"] print(inventory)
Vous pouvez également modifier un objet dans l'inventaire du ninja par son indice. Pour cela, vous pouvez passer l'indice à la méthode ninja.pick_to_inventory(index)
.
ninja.py
Tâche
Swipe to start coding
Solution
Explorer d'autres cours dans le catalogue
Tout était clair ?
Merci pour vos commentaires !
Section 7. Chapitre 2