Week Three
This week we learn about variables β containers that store information so you can use it later in your program.
Presentation
Variables
Variables are containers that store information. You give them a name and assign a value using =.
world = 'πππ'
python = 'Python π'
fire = 'π₯'
name = 'Shirley'worldstores emojis.pythonstores text with an emoji.firestores a fire emoji.namestores a string representing a name.
π‘ Tip: Variables can store text (strings), numbers, or other types of data.
More Examples
name = "Alice"
age = 12
is_student = True
print(f"{name} {age}")Changing Variable Values
You can update a variable by assigning it a new value:
score = 0
score = 10
print(score) # 10Using Variables in f-strings
f-strings let you insert variables directly into text:
name = "Alex"
print(f"Hello, {name}!")This prints:
Hello, Alex!Print / Output
print() shows information on the screen. Itβs how you check what your code is doing.
print("This is output!")Activity
Try changing the values of variables and see how the output changes. Add more print() statements with your own emojis or messages!
variables.py
pet = "dog"
emoji = "πΆ"
count = 3
print(f"I have {count} {pet}s {emoji}")Last updated on