Basic

Values come in kinds

Every value has a kind, and the kind decides what you can do to it. Numbers get added, text gets joined, yes/no values pick branches. The kind is a property of the value, not of the name, and it is what makes two values that look alike behave differently.

What you will see

True

About 2 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

Compare values that look alike but are not the same kind.

1

Print the kind of a whole number.

print(type(4))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2

Print the kind of the quoted four.

print(type("4"))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3

Add the number and add the text. Two different answers from one symbol.

print(4 + 4) print("4" + "4")

Before you run it, say out loud what it will print. Then open the answer.

What it prints
8 44
4

Ask a comparison. It answers with a yes/no value, not an error.

print(4 > 3)

Before you run it, say out loud what it will print. Then open the answer.

What it prints
True
True and False are values you can store and reuse. A condition in an if statement is just such a value being tested.

Data Flow

The computer records the kind with the value, and every operation checks the kind before it runs.
1 You write a value
↓
2 The computer records its kind
↓
3 An operation checks the kind
↓
4 It computes or refuses
Line by line

Read the first example one line at a time. A line that prints shows what appears on screen; the rest set things up quietly.

print(type(4)) <class 'int'>
Why this works
Why kinds exist

A computer stores everything as bits, so the kind is a decision about how to read those bits. 4 and "4" can look identical on screen and be stored differently. Kinds exist so the computer can refuse nonsense, like dividing text by a number, instead of guessing.

The kinds you meet first

Whole numbers and decimal numbers for counting and measuring. Text for names, labels, and anything read from a person. True and False for decisions. Those four cover the start of almost every language, and everything else is built from them.

Examples

Ask the computer

print(type(4))
print(type(4.5))
print(type("4"))

The four kinds here are whole numbers, decimal numbers, and text. type names the kind of any value, which is how you find out what you are holding when a value arrives from somewhere else.

Same look, different kind

print(4 + 4)
print("4" + "4")

The first adds and gives 8. The second joins two pieces of text and gives 44. Both use + and both print a number-looking answer, which is exactly the trap to notice early.

Yes and no are values

print(4 > 3)
print(4 < 3)

A comparison is not a command, it is a value: True or False. That means a comparison can be stored in a name and used later, which is what a condition is built from.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← A name can be filled again
Previous Lesson
A name can be filled again
Next Lesson
An expression makes one value
An expression makes one value →