Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Ordbøker og Ordbokmetoder | Andre Datatyper
Introduksjon til Python

Sveip for å vise menyen

book
Ordbøker og Ordbokmetoder

1234567891011
# Dictionary creation groceryItems = { "Milk": 3.49, "Eggs": 2.99, "Bread": 1.99, "Apples": 0.99 } # Extracting dictionary elements by their keys print("Price of Milk:", groceryItems["Milk"]) print("Price of Bread:", groceryItems["Bread"])
copy
123456789
# A dictionary with various types of keys and values store_info = { "Store Name": "Grocery Galore", # String key and string value 42: "Inventory Count", # Integer key and string value ("Bread", "Milk"): [2.99, 1.59] # Tuple key and list value (prices of bread and milk) } # Extracting dictionary element (list) by its key (tuple) print("Data under key ('Bread', 'Milk'):", store_info[("Bread", "Milk")])
copy
12345678910111213141516171819202122
# Dictionary for a grocery store inventory inventory = { "Apples": 30, "Oranges": 18, "Bananas": 45 } # Get the count of Oranges print("Count of Oranges:", inventory.get("Oranges")) # Update inventory by adding a new item inventory.update({"Mangoes": 20}) print("Updated Inventory:", inventory) # You can also add a new item to the end of the dictionary like this inventory["Pineapples"] = 15 print("Updated Inventory:", inventory) # Remove Bananas from the inventory removed_item = inventory.pop("Bananas") print("Removed Item:", removed_item) print("Current Inventory:", inventory)
copy
Oppgave

Swipe to start coding

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 7
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

Awesome!

Completion rate improved to 2.17

book
Ordbøker og Ordbokmetoder

1234567891011
# Dictionary creation groceryItems = { "Milk": 3.49, "Eggs": 2.99, "Bread": 1.99, "Apples": 0.99 } # Extracting dictionary elements by their keys print("Price of Milk:", groceryItems["Milk"]) print("Price of Bread:", groceryItems["Bread"])
copy
123456789
# A dictionary with various types of keys and values store_info = { "Store Name": "Grocery Galore", # String key and string value 42: "Inventory Count", # Integer key and string value ("Bread", "Milk"): [2.99, 1.59] # Tuple key and list value (prices of bread and milk) } # Extracting dictionary element (list) by its key (tuple) print("Data under key ('Bread', 'Milk'):", store_info[("Bread", "Milk")])
copy
12345678910111213141516171819202122
# Dictionary for a grocery store inventory inventory = { "Apples": 30, "Oranges": 18, "Bananas": 45 } # Get the count of Oranges print("Count of Oranges:", inventory.get("Oranges")) # Update inventory by adding a new item inventory.update({"Mangoes": 20}) print("Updated Inventory:", inventory) # You can also add a new item to the end of the dictionary like this inventory["Pineapples"] = 15 print("Updated Inventory:", inventory) # Remove Bananas from the inventory removed_item = inventory.pop("Bananas") print("Removed Item:", removed_item) print("Current Inventory:", inventory)
copy
Oppgave

Swipe to start coding

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

close

Awesome!

Completion rate improved to 2.17

Sveip for å vise menyen

some-alt