Gets the data type of function: type ()
>>> type(a) <class 'str'>
type () function if you have only the first argument of type object is returned, the three parameters return a new type of object.
grammar:
type(object)
type(name, bases, dict)
parameter
- Name of the class - name.
- bases - tuple base class.
- dict - dictionary, within the class definition namespace variable.
Analyzing Data Type: isinstance ()
>>> a = '你好' >>> isinstance(a,str) True >>> isinstance(a,int) False
isinstance () and type () the difference:
-
type () does not think that is a subclass of parent class type, without regard to inheritance.
-
isinstance () will be considered sub-class is a parent class type, consider inheritance.
To determine whether two of the same type recommended isinstance ().