Check your understanding of the previous reading on types.
Identify the type of each literal value.
| Literal | Type |
|---|---|
5 |
|
False |
|
4.3 |
|
"Hello World" |
|
"4" |
|
"" |
|
None |
|
0 |
|
"True" |
Two things decide the type: quotes, and a decimal point.
True.True, False with no quotes are Boolean; None with no quotes is None.The types:
| Literal | Type |
|---|---|
5 | Integer |
False | Boolean |
4.3 | Float |
"Hello World" | String |
"4" | String |
"" | String |
None | None |
0 | Integer |
"True" | String |
Why each type:
5 and 0 are whole numbers with no quotes and no decimal point: Integer.False is one of the two Boolean values, written with no quotes.4.3 has a decimal point, so it is a Float, even though it "looks like a number" the same way 5 does."Hello World", "4", "" and "True" are all inside quotation marks, so all four are String, no matter what they look like inside the quotes. "4" is text that happens to contain a digit, not the number four; "True" is text that happens to spell the word "True", not the Boolean value; "" is the empty string, still a String with zero characters.None, written with a capital N and no quotes, is the one and only value of the None type.Match each type to its description.
| Type | Description |
|---|---|
| Integer | |
| String | |
| Float | |
| None | |
| Boolean | |
| Python |
Five of these six rows are one of the basic types from the reading; one is a trap.
Python is the name of the programming language, not one of its data types.The descriptions:
| Type | Description |
|---|---|
| Integer | Whole numbers |
| String | Text |
| Float | Decimal numbers |
| None | A special value that means nothing |
| Boolean | True or False |
| Python | This is not a type |
Why each match: Integer, String, Float, None and Boolean are exactly the five basic types from the reading, matched to their one-line descriptions. Python is a deliberate trick row: it is the name of the language itself, not a data type, so "This is not a type" is the only description that fits.
Which of the following are Integers, in Python?
Select every Integer literal, then check.
Two things disqualify a number from being an Integer: quotation marks around it (that makes it a String), or a decimal point in it (that makes it a Float).
Write the output of the print statement:
print("5")
What does print("5") write to the console?
"5" is a String literal - the quotes are part of the code, not part of the value. Printing it shows only the character 5, with no quotes around it.
How many possible values are there for each type?
| Type | Possible values |
|---|---|
| Integer | |
| Boolean | |
| String | |
| Float | |
| None |
Only one type in this table has just two possible values, and only one has just a single possible value. The rest have an enormous range of possible values.
None "a special type that has only one value".The counts:
| Type | Possible values |
|---|---|
| Integer | More than 100 |
| Boolean | 2 |
| String | More than 100 |
| Float | More than 100 |
| None | 1 |
Why each count: Integer, String and Float each have effectively unlimited possible values (every whole number, every possible piece of text, every decimal number), so all three are "More than 100". Boolean has exactly two possible values, True and False. None has exactly one possible value: None itself.
Match each type to its abbreviation in Python:
| Type | Abbreviation |
|---|---|
| Integer | |
| None | |
| Boolean | |
| String |
Most of Python's type names are shortened. One of them is not.
The abbreviations:
| Type | Abbreviation |
|---|---|
| Integer | int |
| None | None |
| Boolean | bool |
| String | str |
Why each abbreviation: Integer, Boolean and String are shortened to int, bool and str respectively, exactly as the reading introduces them. None is the odd one out: it is already short, so its "abbreviation" is just None itself.