In the previous sections we have seen how variables can be used to work with data. But what sort of data can we work with in Python?
Python supports a variety of data types out of the box, such as:
True
or False
)You can check the type of any value in Python
by using the type
function:
quantity = 42 print(type(quantity))
This will print int
, as the value 42
is
an integer.
You can also assign the result of the type
function to a new variable:
quantity_type = type(quantity)
Define a variable called unit_cost
and set it
to the value 4.99
. Then, create a variable
called unit_cost_type
and set it to the type
of the unit_cost
variable.