Every value in Python has a type. type() tells you what it is, and isinstance() checks whether a value is of a particular type.
The program
python
x = 3.14 print(type(x)) print(isinstance(x, float)) print(isinstance(x, int))
output
<class 'float'> True False
How it works
type(x)returns the type of the value.3.14has a decimal point, so it is a float.isinstance(x, float)answers yes or no (TrueorFalse): isxa float?
The common types
python
print(type(42)) print(type("hello")) print(type([1, 2, 3])) print(type(True))
output
<class 'int'> <class 'str'> <class 'list'> <class 'bool'>
In real code, prefer isinstance() when you need to make a decision. It also accepts several types at once: isinstance(x, (int, float)) is True for any number.