Home > Backend Development > Python Tutorial > Python Dictionary

Python Dictionary

WBOY
Release: 2024-08-06 20:56:20
Original
756 people have browsed it

Python Dictionary

Annachi Kadai

In Tamil Nadu there was shop called Annachi Kadai. The owner of the shop is Pandiyan. Now we learn Python using this case study.

Morning:

In the early morning the goods for shop will come. Then Pandiyan will take a note on the goods.

One day the goods came to his shop and he take a note on it. They are:-

inventory = {
    "apples": 20,
    "bananas": 30,
    "carrots": 15,
    "milk": 10
}
Copy after login

He want to check the list.

print(inventory)
 {
    'apples': 20,
    'bananas': 30,
    'carrots': 15,
    'milk': 10
}
Copy after login

Noon:

As the time going the delivery also increases. So he add more inventories.

inventory["bread"] = 25
inventory["eggs"] = 50
Copy after login

Then he want to check the list

print("Updated Inventory:", inventory)

Updated Inventory: {'apples': 20, 'bananas': 30, 'carrots': 15, 'milk': 10, 'bread': 25, 'eggs': 50}
Copy after login

Afternoon:

Then in the afternoon the quantities of the goods is going less. So he buyed some goods and he want that to add it on the list.

inventory["apples"] += 10 
inventory["milk"] += 5
Copy after login

Then he want to check the list

print("Inventory after Restocking:", inventory)

Inventory after Restocking: {'apples': 30, 'bananas': 30, 'carrots': 15, 'milk': 15, 'bread': 25, 'eggs': 50}
Copy after login

Evening:

In evening many of goods have sold. So he want to remove it from the list.

del inventory["carrots"]
Copy after login

then he want to check the list.

print("Inventory after Removal:", inventory)

Inventory after Removal: {'apples': 30, 'bananas': 30, 'milk': 15, 'bread': 25, 'eggs': 50}
Copy after login

Night:

Before closing the shop. He wants to check the inventory is the inventories are correct.

is_bananas_in_stock = "bananas" in inventory
is_oranges_in_stock = "oranges" in inventory
print(f"Are bananas in stock? {is_bananas_in_stock}")
print(f"Are oranges in stock? {is_oranges_in_stock}")

 Are bananas in stock? True
 Are oranges in stock? False
Copy after login

This things only we learnt in the python class.
Thank You

The above is the detailed content of Python Dictionary. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template