
Code
Kinds of Values
Every value in Python has a type, what kind of thing it is. You've met some already:
| Type | What it is | Examples |
|---|---|---|
str |
text (a string) | "Pip", "42" |
int |
whole number (integer) | 7, -3, 0 |
float |
number with a decimal point | 2.5, 10.0 |
bool |
yes/no (boolean) | True, False |
NoneType |
"nothing here yet" | None |
True, False and None start with a capital letter and
have no quotes.
Ask Python for a value's type with type():
print(type(7)) # <class 'int'>
print(type("7")) # <class 'str'> quotes make it text!
print(type(7.0)) # <class 'float'>
print(type(False)) # <class 'bool'>
None is useful when something doesn't exist yet, like a
lighthouse that has no keeper assigned.
Assignment
Fill in the lighthouse's record card:
name: the text"Moonwell"floors: the whole number4height: the decimal number12.5is_lit:False(it's dark right now)keeper:None(no keeper yet)
Fill in the lighthouse's record card:
name: the text"Moonwell"floors: the whole number4height: the decimal number12.5is_lit:False(it's dark right now)keeper:None(no keeper yet)
main.py Python sleeping
Press Run to try your code, then Check to test it.