Methods to view Python variable types: 1. Use type(), the syntax "type(object)", to return the type of variable object; 2. Use isinstance(), the syntax "isinstance(object,classinfo)" , check whether the variable object is a known type.
How Python determines the type of a variable
There are two ways to determine the type of a variable in Python: type() and isinstance()
How to use
For basic data types, both have the same effect
type()
Return the type of object
isinstance()
isinstance() function to determine whether an object is a known type, similar to type() .
The difference
The difference between isinstance() and type() is:
type() The subclass will not be considered to be a parent class type
isinstance() will consider the subclass to be a parent class type
The above is the detailed content of How to check the type of a Python variable. For more information, please follow other related articles on the PHP Chinese website!