Kursinhalt
Python-Datenstrukturen
Python-Datenstrukturen
Die Clear() Methode
Dictionaries bieten auch eine praktische clear()
-Methode, die alle Elemente entfernt und Ihnen ein leeres Dictionary hinterlässt. So funktioniert es.
# 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)
Aufgabe
Swipe to start coding
Wir haben großartige Arbeit mit dem authors_books
-Dictionary geleistet, aber es ist Zeit, sich davon zu verabschieden.
Ihr Ziel:
- Leeren Sie das
authors_books
-Dictionary. - Verwenden Sie die
clear()
-Methode, um dies zu tun.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 8
Die Clear() Methode
Dictionaries bieten auch eine praktische clear()
-Methode, die alle Elemente entfernt und Ihnen ein leeres Dictionary hinterlässt. So funktioniert es.
# 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)
Aufgabe
Swipe to start coding
Wir haben großartige Arbeit mit dem authors_books
-Dictionary geleistet, aber es ist Zeit, sich davon zu verabschieden.
Ihr Ziel:
- Leeren Sie das
authors_books
-Dictionary. - Verwenden Sie die
clear()
-Methode, um dies zu tun.
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 8