MulaiMulai sekarang secara gratis

Modifying dictionaries

Like lists, dictionaries can be changed. You can add new key:value pairs, update existing pairs, remove pairs. In this exercise, you'll explore creating and modifying dictionaries by creating the grocery list below.

  • 1 gallon of milk
  • 4 apples
  • 1 loaf of bread
  • 3 avocados
  • 2 candy bars

Latihan ini adalah bagian dari kursus

Python for MATLAB Users

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create dict with milk and apples
groceries = {____:____, 
             ____:____}

print(groceries)
Edit dan Jalankan Kode