Python · Stage 1 · Storing Information · Lesson 12 of 50

Checking a Value’s Type

Ask Python what kind of value is stored by using type().

Python’s type function reports a value’s type:

print(type(42))
Line-by-line explanation
  1. 42 is an integer.
  2. type(42) asks for its type.
  3. print displays the answer.
  4. The output contains int.

You can check a stored value too:

price = 4.5
print(type(price))
Line-by-line explanation
  1. The first line stores the float 4.5.
  2. type(price) checks the stored value.
  3. print displays an answer containing float.

The answer looks like <class 'float'>. Focus on float; “class” is a later topic.