Vider Complètement un Dictionnaire
Les dictionnaires proposent également une méthode pratique clear() qui supprime tous les éléments, vous laissant avec un dictionnaire vide. Voici comment cela fonctionne.
12345678910111213141516# Creating a dictionary for book details book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Printing the dictionary before clearing print("Before clearing:", book) # Clearing all items from the dictionary book.clear() # Printing the dictionary after clearing print("After clearing:", book)
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 8
single
Vider Complètement un Dictionnaire
Glissez pour afficher le menu
Les dictionnaires proposent également une méthode pratique clear() qui supprime tous les éléments, vous laissant avec un dictionnaire vide. Voici comment cela fonctionne.
12345678910111213141516# Creating a dictionary for book details book = { "title": "Pride and Prejudice", "author": "Jane Austen", "year": 1813, "genre": "Romance" } # Printing the dictionary before clearing print("Before clearing:", book) # Clearing all items from the dictionary book.clear() # Printing the dictionary after clearing print("After clearing:", book)
Tâche
Glissez pour commencer à coder
Vous avez travaillé avec le dictionnaire authors_books, et il est maintenant temps de le vider complètement.
- Vider le dictionnaire
authors_books. - Utiliser la méthode
clear()pour cela.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 8
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion