Python Part I · Module 2 · Variables and Data Types
Values: The Things a Program Works With
Module 1 left you able to run a Python file and display a fixed message. That is a program that cannot yet do anything useful, because it has nothing to work with. This module is about giving it something, and it starts one step earlier than most courses do — not with variables, but with the things variables refer to. A number is a value. A piece of text is a value. True is a value. Each kind behaves differently, and Python cares about the difference in ways that will matter within about ten minutes. Spending one chapter on values before naming any of them means the next chapter has something concrete to name, rather than asking you to hold an empty abstraction.
Foundation8 min readPythonPart IFundamentalsValuesData Types
Part I · Module 2 · Chapter 2.1 · Values: The Things a Program Works With
1. A Program Needs Something to Work With
The program you wrote in Module 1 displayed a message you typed in advance. It could not count anything, remember anything or decide anything, because it had no information in it — only instructions.
Real programs work with information: how many errors a run produced, which test was launched, whether it passed. Before Python can hold any of that, you need to know what the individual pieces of information look like.
Those pieces are called values.
2. Four Kinds You Have Already Half Seen
You met some of these in Module 1 without them being named. Here they are properly, one at a time. Each one goes inside print() so you can run it — that is the only tool you need, and Chapter 1.8 taught it.
A whole number
print(4210)42104210 is a number. No quotes. Python understands it as a quantity — it could add it to something, compare it against something.
Text
print("axi_smoke")axi_smoke"axi_smoke" is text. The quotes tell Python where the text starts and stops; Chapter 1.8 §1 covered that. Python does not try to interpret what is inside — it is just characters.
A true-or-false answer
print(True)TrueTrue is a value meaning exactly what it looks like. There is also False. Note the capital letter — that is required, and §4 comes back to it.
Deliberately nothing
print(None)NoneNone is Python's way of saying there is no meaningful value here. Not zero, not empty text — a specific value whose job is to mark an absence. It is genuinely useful, and Chapter 2.8 gives it a proper treatment.
3. The Same Characters, Different Values
Here is the idea this whole module depends on. Look at these two lines:
print(4210)
print("4210")4210
4210The output is identical. But the two values are not the same kind of thing.
The first is a number. The second is text that happens to contain the characters 4, 2, 1, 0.
Why does that matter, if they look the same when printed? Because Python will let you do different things with them. You can do arithmetic with a number. You cannot do arithmetic with text, even text that looks numeric.
You will be able to check the difference for yourself in Chapter 2.10, and to convert between them in Chapter 2.11.
4. Capitalisation Is Not Optional
True, False and None are spelled with a capital first letter and no quotes. Python is case-sensitive — Chapter 1.8 §6 showed that Print and print are different names — and the same applies here.
print(true)NameError: name 'true' is not defined. Did you mean: 'True'?Python looked for something called true, found nothing, and stopped. That is the NameError from Chapter 1.11 §4, and here it is telling you that the value is spelled True.
5. The Four Kinds, Together
Now that you have met each one individually, they are worth seeing side by side. Python has a name for each kind, and you will see those names constantly from Chapter 2.10 onward.
| Value you write | Python calls its kind | What it is for |
|---|---|---|
4210 | int | a whole number |
182.4 | float | a number with a fractional part |
"axi_smoke" | str | text |
True / False | bool | a true-or-false answer |
None | NoneType | a deliberate absence of value |
182.4 is the one you have not printed yet. It is a number written with a decimal point, and Chapter 2.6 explains why Python treats it as a different kind from 4210.
Do not try to memorise this table. Each row gets its own chapter. It is here so the shape of the module is visible.
6. Predict, Run, Observe
Write down what you expect from each line, then run them all in one file.
print(500)
print("500")
print(0.8)
print(False)
print(None)500
500
0.8
False
NoneThe first two are the interesting pair — identical output, different kinds of value. If you predicted that correctly, you have the main idea of the chapter.
7. Exercise
Exercise 1 — name the kind. For each, say which of the five kinds it is, without running anything:
(a) 0 (b) "0" (c) 0.0 (d) False (e) "False" (f) None (g) "None"
Three of those are text. Make sure you can say which.
Exercise 2 — predict the failure. Predict what happens for each, then run them:
(a) print(TRUE) (b) print("TRUE") (c) print(None) (d) print(none)
Two will fail. For each failure, name the error and say what Python was looking for.
Exercise 3 — choose a kind. For each fact from an engineering run, say which kind of value you would use to hold it: (a) how many errors were found; (b) the name of the test; (c) whether the run passed; (d) how long it took in seconds; (e) the reason it failed, when it has not failed.
(For (e): the honest answer is None — there is no reason, and that is different from an empty piece of text.)
8. Summary
- A value is one piece of information a program works with. Programs need values; instructions alone are not enough.
- Five kinds cover almost everything a beginner needs: whole numbers, numbers with a fractional part, text, true-or-false, and
None. - Quotes make text.
4210is a number;"4210"is text containing four characters. - Identical output does not mean identical kind. This is the single most important idea in the chapter, and the source of a great many real bugs.
True,FalseandNoneare capitalised and are not text. Lowercasetrueis aNameError.Nonemarks a deliberate absence, which is not the same as zero or empty text.
You now know what values are. What you cannot yet do is keep one — every value in this chapter was printed and immediately forgotten. The next chapter gives values names, so a program can refer to one again later.
Where this fits
Part of the Python curriculum.
