Python Variables and Core Types
Work with names, integers, floats, strings, booleans, and None while learning how Python binds names to objects instead of fixed storage boxes.
Before this lesson
Describe name binding accurately
Choose useful built-in scalar types
Distinguish equality from object identity
The short answer
A Python variable is a name bound to an object. The object has a type, and a name can later be rebound. Prefer descriptive names, use immutable values by default, and inspect types when behavior—not guesswork—requires it.
Build the mental model
Assignment binds a name to an object; it does not copy a typed box into existence. Integers, floats, strings, booleans, and None are immutable. Reassigning total creates a new binding while aliases to a mutable object can still observe mutations.
The central idea in this lesson is names and objects. Read the rule, predict a concrete outcome, and then run the smallest example that can confirm or reject the prediction. This separates knowledge from familiarity with syntax.
Make the design choice explicit
Use int for whole counts, float for approximate measurements, str for text, bool for conditions, and None for an explicitly missing value. Money needs a deliberate decimal policy rather than accidental binary floating-point assumptions.
course = "Python"
lesson_count = 20
completion = 0.25
is_active = True
next_lesson = None
print(course, lesson_count)
print(f"Progress: {completion:.0%}")
print(next_lesson is None)Expected output
Python 20 Progress: 25% True
Trace the example before running it. Identify each input, transformation, returned value, and side effect. Then change one boundary value and explain why the new behavior follows from the rule rather than memorizing the output.
Recognize failure modes
The type function is useful while exploring, but production branches based on exact types are often brittle. Equality asks whether values compare the same; is asks whether two references identify the same object and is primarily appropriate for None.
Use a professional practice loop
Turn the concept into a repeatable workflow: write down the expected behavior, implement one coherent change, run a representative example, and retain a regression check. If the result surprises you, capture the exact input and error before changing anything.
Review the program for names, boundaries, and hidden side effects. A solution is complete when another developer can understand its contract, reproduce its setup, and verify both the successful path and one meaningful failure path.
Quick knowledge check
Answer before you reveal.
01Does assigning a new value change a variable’s permanent type?
No. Python names are dynamically bound and may later refer to an object of another type.
02What four steps make the practice loop reliable?
Predict the behavior, make one coherent change, run it, and retain a check that detects regression.
Exercise
Practice challenge
Model a book with title, page count, rating, availability, and an optional borrower, then print a readable one-line summary.
Requirements
- The successful path produces the documented result
- At least one boundary or invalid case is handled deliberately
- Calculation or domain logic is separated from console interaction
Optional extension: Add one automated regression check for the most important rule.
Open in Python compilerLesson checkpoint
One small step locks it in
Mark this lesson complete, then keep the momentum going.
Clear up the details
Frequently asked questions
Is names and objects only important in large programs?
No. Small programs reveal the same rules with less noise, and learning the rule early prevents fragile habits from becoming architecture.
Should I memorize every API used here?
No. Memorize the mental model and how to verify behavior. Use documentation for exact names and parameters when needed.
How do I know the exercise is finished?
Meet every success criterion, test at least one boundary or failure case, and explain why the output follows from the code.