Data Type Explorer
Run the Data Type Explorer MicroSim Fullscreen
About This MicroSim
Every value in MicroPython has a data type. The type tells Python what kind of information the value is and what you can do with it. This MicroSim sorts values into the four types from the chapter:
| Type | What it looks like | Robot example |
|---|---|---|
int |
A whole number, no decimal point | distance_cm = 15 |
float |
A number with a decimal point | scale_factor = 0.92 |
str |
Text inside quotes | robot_name = "Sparky" |
bool |
Exactly True or False |
is_moving = True |
Tiny changes matter. 15 is an int, 15.0 is a float, and "15" is a
string. True is a bool, but true (lowercase) is an error.
How to Use
- Predict first. Click the bin you think the value belongs in. It gets an orange outline.
- Type a value in the field, or click one of the robot value buttons.
- Press Check type. The value slides into its bin. The dark panel shows
what the REPL would print for
type(value), plus the reason. - Tick "Show what value + 1 does" to see which types can do math. Try
it with
"15"and withTrue. - Try to break it. Type
true,TRUE, or12 cmand read the error.
Challenge: Predict the type of each value: 0.92, "65535", False,
and 20. Then check. Which one changed type because of the quotes? The four
types are described in
Chapter 3: The Four Core Data Types.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Learning Objective
Students will classify MicroPython literals as int, float, str, or
bool, and will explain how a single surface feature—a decimal point,
quotation marks, or capitalization—determines the type (Bloom's Taxonomy:
Understand).
Grade Level
Grades 8–12.
Duration
10–15 minutes.
Prerequisites
- The "Variables and Assignment" and "The Four Core Data Types" sections of Chapter 3.
- Familiarity with the REPL prompt
>>>, from the REPL section of the same chapter.
Background
Novices tend to classify values by meaning ("15 is a distance, so it is a
number") rather than by syntax. Python, however, decides the type purely from
how the literal is written. The MicroSim's reason sentences always point to
the syntactic cue, and the value + 1 toggle shows the practical
consequence: "15" + 1 raises a TypeError, which is exactly the bug
students meet when they read text from a display or a network and try to do
arithmetic on it. The True + 1 == 2 case is included deliberately; it
previews the fact that bool is a subtype of int in Python, without
requiring students to learn inheritance.
Activities
- Predict-and-check (4 min). Students click a bin to predict each of the ten robot values before pressing Check type, tallying correct predictions.
- Minimal pairs (4 min). Students test
15/15.0/"15"andTrue/true/"True", then write one sentence for each set naming the feature that changed the type. - Math test (3 min). With "+ 1" on, students record which types allow
+ 1and which produce an error. - Challenge (2 min). Answers:
0.92float,"65535"str,Falsebool,20int. The quotes changed"65535". - REPL confirm (2 min). Students type
type("15")and"15" + 1in Thonny to confirm the MicroSim matches the real board. The exact wording of an error message can vary slightly between MicroPython versions, but the error type (TypeError,NameError) is always the same.
Assessment
- Formative: Prediction tallies from Activity 1 (target: 8 of 10).
- Exit ticket: "A sensor library gives you
"42". What type is it, what happens if you add 1, and how could you tell from how it is written?" - Rubric (4-point): Exemplary — classifies all four types and error
cases, names the syntactic cue, and predicts the
+ 1result; Proficient — classifies all four types and names the cue; Developing — classifies by meaning and misses quoted numbers; Beginning — cannot distinguishintfromfloatorstr.
References
- Chapter 3: MicroPython and Development Environment Setup — integers, floats, strings, and booleans in robot code.
- Python Built-in Types — official description of numeric, text, and boolean types.
- Data type — Wikipedia — what a data type is and why languages use them.
- MicroPython builtin functions and exceptions —
type(),NameError,TypeError, andSyntaxErrorin MicroPython. - Python Data Type Explorer (Learning MicroPython) — the MicroSim this version was adapted from.