Every value has a type: whole numbers, decimals, text, truth values and "nothing".
Whole numbers: 25, -10, 1000000
Numbers with a decimal point: 19.99, -5.5
Text in quotes: "Hello", 'Alice'
Truth values: True, False
The absence of a value: None
In the panels that follow, each variable box shows its type underneath.
# integer
age = 25
type(age)
# ans: <class 'int'>
count = -10
# ans: negative integer
big_num = 1000000
# ans: large integer
# float
price = 19.99
type(price)
# ans: <class 'float'>
pi = 3.14159
# ans: float value
negative = -5.5
# ans: negative float
# string
message = "Hello"
type(message)
# ans: <class 'str'>
name = 'Alice'
# ans: single quotes
text = """multi
line"""
# ans: multiline string
Single, double or triple quotes all make a str; triple quotes can span lines (stored as \n).
# boolean
is_valid = True
type(is_valid)
# ans: <class 'bool'>
is_empty = False
# ans: False value
# None type
x = None
type(x)
# ans: <class 'NoneType'>
# ans: represents absence of value
result = None
# ans: no value yet
# type() function
x = 5
type(x)
# ans: <class 'int'>
y = "hello"
type(y)
# ans: <class 'str'>
z = 3.14
type(z)
# ans: <class 'float'>
Name the type, then press → to run the line and check the box.
# what type is this?
x = 5.0
# ans: <class 'float'>
# what type is this?
y = "123"
# ans: <class 'str'>
# what type results?
result = 10 / 2
# ans: <class 'float'>
# what type is this?
z = True + False
# ans: <class 'int'> (True=1, False=0)
# what type?
a = 5
b = 2
c = a / b
# ans: <class 'float'>
# what type?
x = 10
y = 3
z = x // y
# ans: <class 'int'>
# tricky: what type?
value = "5" + "3"
# ans: <class 'str'> (result is "53")
# what is the type?
x = None
# ans: <class 'NoneType'>
# what type is this expression?
result = 5 > 3
# ans: <class 'bool'>
# what happens?
x = int(True)
# ans: 1, type is <class 'int'>
# mixing types?
x = 5 + 2.5
# ans: 7.5, type is <class 'float'>
# edge case?
x = bool([])
# ans: False, type is <class 'bool'>
# what type?
x = 0
# ans: <class 'int'>
# empty string type?
s = ""
# ans: <class 'str'>
# what type?
x = float(5)
# ans: 5.0, <class 'float'>
/ makes a floatEven 10 / 2 is 5.0; use // for a whole-number result.
"123" is text, and "5" + "3" joins text into "53".
True counts as 1 and False as 0 in arithmetic.
type(value) tells you the type of anything.