This article explains how to check the type of a variable in the Python programming language.
What are Types?
The type of a variable determines what it can or can’t do.
It determines what value the variable may take and what can be done with that value.
Using the type() Function
Pass a variable or value to the type() function, and the variable’s type will be returned:
myNumber = 4 type(myNumber) # int myString = 'foo' type(myString) # str
Using the isinstance() Function
For more examples, check out the similar isinstance() function:
To compare the type of a variable to a known type, you can use the isinstance() function.