Utilisation de la Méthode clear() : Vider Complètement un Dictionnaire
Les dictionnaires offrent é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)
Swipe to start coding
Nous avons fait un excellent travail avec le dictionnaire authors_books
, mais il est temps de lui dire au revoir.
- Videz le dictionnaire
authors_books
. - Utilisez la méthode
clear()
pour cela.
Solution
Merci pour vos commentaires !
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
Awesome!
Completion rate improved to 3.23
Utilisation de la Méthode clear() : Vider Complètement un Dictionnaire
Glissez pour afficher le menu
Les dictionnaires offrent é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)
Swipe to start coding
Nous avons fait un excellent travail avec le dictionnaire authors_books
, mais il est temps de lui dire au revoir.
- Videz le dictionnaire
authors_books
. - Utilisez la méthode
clear()
pour cela.
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 3.23single