Python variables
Imagine you're a chef cooking up a storm in your kitchen.
Each ingredient you use can be seen as a different type of
variable in Python!
1. Integer (int): These are like whole numbers in your
recipe, such as the number of eggs you need or the
temperature you set your oven to. For example:
Python code:
eggs = 6
temperature = 350
2. Float: Floats are like measurements with decimal points,
just like when you add a cup of milk or a tablespoon of
oil. For example:
Python code:
milk_cup = 1.5
oil_tablespoon = 0.25
3. String (str): Strings are like the names of ingredients or
the steps in your recipe. They're made up of letters,
numbers, or symbols, enclosed in quotes. For example:
Python code:
ingredient_name = "flour"
recipe_step = "Mix all ingredients together."
4. Boolean (bool): Booleans are like switches in your
kitchen - they can either be on (True) or off (False). For
example:
Python code:
oven_on = True
recipe_finished = False
5. List: Lists are like shopping lists - they can hold multiple
items in a specific order. For example:
Python code:
ingredients_list = ["flour", "sugar", "eggs", "milk"]
6. Tuple: Tuples are like sealed envelopes - once you've
packed them, you can't change what's inside. For
example:
Python code:
recipe_steps = ("Mix ingredients", "Preheat oven", "Bake
for 30 minutes")
7. Dictionary (dict): Dictionaries are like recipe books -
they store information in pairs of keys and values, just
like a recipe title and its ingredients. For example:
Python code:
recipe = {"title": "Chocolate Cake", "ingredients":
["flour", "sugar", "eggs", "chocolate"], "oven_temp":
350}