Using the clear() Method: Emptying a Dictionary Completely
Sanakirjat tarjoavat myös kätevän clear()
-menetelmän, joka poistaa kaikki kohteet, jättäen sinulle tyhjän sanakirjan. Näin se toimii.
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)
Tehtävä
Swipe to start coding
Olemme tehneet hienoa työtä authors_books
-sanakirjan kanssa, mutta on aika sanoa sille hyvästit.
- Tyhjennä
authors_books
-sanakirja. - Käytä
clear()
-menetelmää tähän.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 2. Luku 8
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 3.23
Using the clear() Method: Emptying a Dictionary Completely
Pyyhkäise näyttääksesi valikon
Sanakirjat tarjoavat myös kätevän clear()
-menetelmän, joka poistaa kaikki kohteet, jättäen sinulle tyhjän sanakirjan. Näin se toimii.
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)
Tehtävä
Swipe to start coding
Olemme tehneet hienoa työtä authors_books
-sanakirjan kanssa, mutta on aika sanoa sille hyvästit.
- Tyhjennä
authors_books
-sanakirja. - Käytä
clear()
-menetelmää tähän.
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Awesome!
Completion rate improved to 3.23Osio 2. Luku 8
single