Python’s type function reports a value’s type:
print(type(42))Line-by-line explanation
42is an integer.type(42)asks for its type.printdisplays the answer.- The output contains
int.
You can check a stored value too:
price = 4.5
print(type(price))Line-by-line explanation
- The first line stores the float
4.5. type(price)checks the stored value.printdisplays an answer containingfloat.
The answer looks like <class 'float'>. Focus on float; “class” is a later topic.