Hello, World & Variables
Layer 0 begins. Before we can explore any Python data structure, we need the absolute basics: running a line of code, naming a value, and knowing what kind of value it is.
A line of code, run โ and a result you can see.
1. Learning Objective
By the end of this session you will be able to:
- Run a Python file and see output with print()
- Create a variable and explain what "assignment" actually does
- Identify the four core built-in types: str, int, float, bool
- Use type() to check what kind of value a variable holds
- Explain why variable names matter for reading code, not just writing it
2. Pre-Coding Quiz
Answer these before reading the concept explanation or writing any code. It is fine to get these wrong โ that is the point. You need 4/5 to proceed to the lab.
What does print("Hello, World") do?
print() is a built-in function that displays whatever you pass it to the console. It is the most basic way to see what a Python program is doing.Given age = 30, what is happening on this line?
= is assignment, not comparison. It creates a name (age) that now refers to the value 30. Unlike some languages, Python does not require you to declare a type upfront.What does type("30") return, as opposed to type(30)?
str), regardless of what characters are inside them โ even digits. "30" is text that looks like a number; 30 is an actual number (int).Which of these is a float, not an int?
float is a number with a decimal point, like 2.3. A whole number with no decimal point is an int. True is a bool, and "Kenya" is a str.Why does a variable name like population matter more than a name like x, given that Python runs both identically?
x = 54 and population = 54 identically โ the computer does not care. But code is read far more often than it is written, and a clear name is free documentation for every future reader.3. The Concept โ Running Code, Variables, and Types
A Python file runs top to bottom, one line at a time โ print() is your window into what is happening.
print() โ seeing what your program is doing
Every Python file is a list of instructions, run top to bottom. print() is how a program communicates with you โ it writes text to the console, the simplest possible feedback loop.
print("Hello, World")
print("This is a second line")
# print can take more than one thing, separated by commas โ it joins them with a space
print("The answer is", 42)
Variables โ naming a value so you can use it again
A variable is a name that refers to a value. Once created, you can use the name instead of retyping the value everywhere โ and if the value needs to change, you only update it in one place. (Population figures throughout this course are in millions, to keep the numbers easy to read.)
name = "Kenya"
population = 54
print(name)
print(population)
print(name, "has a population of", population)
# The value can change โ the variable is reassigned, not "locked"
population = 55
print(population) # 55
The four core types you will see constantly
Every value in Python has a type. These four cover almost everything you will touch in your first weeks: str (text), int (whole numbers), float (decimal numbers), and bool (True or False).
name = "Kenya" # str โ text, always in quotes
population = 54 # int โ a whole number
growth_rate = 2.3 # float โ a number with a decimal point
is_independent = True # bool โ exactly True or False, capitalized, no quotes
print(type(name)) # <class 'str'>
print(type(population)) # <class 'int'>
print(type(growth_rate)) # <class 'float'>
print(type(is_independent)) # <class 'bool'>
Quotes make all the difference
The exact same characters can be a string or a number depending entirely on whether they are in quotes. This distinction matters constantly โ a number in quotes cannot be used in arithmetic without converting it first (we cover that next session).
population_text = "54" # str โ this is TEXT that happens to look like a number
population_number = 54 # int โ this is an actual number
print(type(population_text)) # <class 'str'>
print(type(population_number)) # <class 'int'>
4. Lab
What you will build
A file called hello.py.
Step-by-step instructions
Create the file and print a greeting
# hello.py
print("Hello, World")
print("My name is Ada and I am learning Python")
Create four variables, one of each core type
Use real, meaningful values โ pick a country, like the rest of this course will.
country_name = "Kenya"
population = 54
growth_rate = 2.3
is_independent = True
Print each variable with a label using print()'s comma-joining
print("Country:", country_name)
print("Population:", population)
print("Growth rate:", growth_rate)
print("Independent:", is_independent)
Print the type of each variable
Before running: predict what each type() call will print.
print(type(country_name))
print(type(population))
print(type(growth_rate))
print(type(is_independent))
Reassign one variable and prove the old value is gone
population = 55
print("Updated population:", population)
5. Expected Files Changed
| File | Action | Why |
|---|---|---|
hello.py |
Created | The only file for this session. Plain Python, no imports. |
docs/sessions/session-01/index.html |
Created | This session document. |
6. Commit Checkpoint
Once the lab is complete and you can explain every line, make this exact commit:
git add hello.py docs/sessions/session-01/index.html
git commit -m "session-01: print output, create variables, and check their types"
7. Code Review Checklist
Go through your code line by line and check each item:
8. Post-Coding Quiz
Same 5 questions. Take it again now that you have written and run the code. You need 4/5 to mark this session complete.
What does print("Hello, World") do?
print() is a built-in function that displays whatever you pass it to the console. It is the most basic way to see what a Python program is doing.Given age = 30, what is happening on this line?
= is assignment, not comparison. It creates a name (age) that now refers to the value 30. Unlike some languages, Python does not require you to declare a type upfront.What does type("30") return, as opposed to type(30)?
str), regardless of what characters are inside them โ even digits. "30" is text that looks like a number; 30 is an actual number (int).Which of these is a float, not an int?
float is a number with a decimal point, like 2.3. A whole number with no decimal point is an int. True is a bool, and "Kenya" is a str.Why does a variable name like population matter more than a name like x, given that Python runs both identically?
x = 54 and population = 54 identically โ the computer does not care. But code is read far more often than it is written, and a clear name is free documentation for every future reader.9. Reflection Questions
Think through these after the post-quiz. No right answer โ they are for discussion.
- Why do you think Python does not require you to write the type of a variable when you create it, unlike some other languages you may have heard of?
- What would happen if you tried to print a variable name you never created? Try it and read the error message carefully โ what does it call this kind of error?
- Why might a program with variables named a, b, c be harder to review than one with country_name, population, growth_rate?
- Can you think of a value that seems like a number but should actually be stored as a string? (Hint: think about a postal code or a phone number.)
10. What Breaks If This Knowledge Is Missing?
- Every single session after this one: Variables and print() are used in literally every remaining lab in this curriculum without being re-explained. If reading a line like
population = 54does not feel automatic yet, slow down here before continuing. - Type confusion bugs: Confusing "54" (text) with 54 (a number) is one of the most common beginner mistakes โ it causes errors the moment you try to do arithmetic with the text version, which the next session covers directly.
11. What We Learned
Python concept mastered: Running Python code, print() for output, variables as named values, and the four core built-in types.
Unlocks: You can now read and write the most basic unit of every Python program: a line that creates or displays a value.
Next session: Session 02 โ Operators, Strings & Type Conversion. We do arithmetic and text manipulation, and learn to convert between types deliberately.