Data Types
What kind of value is in the box — numbers, words, true/false, lists.
Prerequisites:Variables
Story — the recycling sorter
A conveyor belt rolls past a row of bins labeled int, string, bool, list. A small robot picks up each thing as it goes by and drops it into the bin that matches what it is. A number into the int bin. A word in quotes into the string bin. A checkmark into the bool bin.
Try to put a string into the int bin and a buzzer goes off. That is a type — a tag that says what kind of value this is, so the language knows what operations make sense.
Sorter says
See it — sort the belt
Press Step to advance one item. The last item is a deliberate mismatch — watch what happens.
Text-only trace
Try it — declare three values
The four lines below set up three differently-typed values and print them. Put them in a working order.
Drag the pieces — or tab to one and use the ↑/↓ buttons — to put the program in order.
is_open = Truename = "Asha"age = 7print(age, name, is_open)
Code it — five languages, one idea
The same four declarations in five popular languages. Notice how static languages (Java, C++) write the type next to the name; dynamic ones (Python, JavaScript, Go) infer it from the value.
age = 7 # int
name = "Asha" # str
is_open = True # bool
scores = [9, 7, 8] # list
print(type(age), type(name))Walk through it line by line
Each click of Next declares one variable. Watch the type tags grow.
1age = 72name = "Asha"3is_open = True4scores = [9, 7, 8]5print(type(age), type(name))
Quiz it — make it stick
No Dumb Questions
Real questions other learners asked on this page.
Why does Python not need me to write the type, but Java does?
Python is dynamically typed — it figures out the type from the value you assigned (7 is clearly an int). Java is statically typed — it wants you to commit up front so the compiler can catch mistakes before the program runs. Both work; both have trade-offs.What is the difference between an int and a float?
An int is a whole number (1, 42, -7). A float has a decimal point (3.14, -0.5). Floats can represent fractions but with tiny rounding errors, which is why money is usually stored as integers (cents) rather than floats.Why do strings need quotes?
Quotes are how the computer tells "the word name" apart from "the variable named name". Without quotes, `name` is a label; with quotes, `"name"` is a piece of text. Single or double quotes both work in most languages.