Python 判斷數據類型有type和isinstancepython
基本區別在於:數組
type():不會認爲子類是父類ui
isinstance():會認爲子類是父類類型spa
class Color(object): pass class Red(Color): pass print type(Color()) == Color print type(Red()) == Color print isinstance(Red(),Color)
執行結果以下:code
D:\software\Python2.7.13\python.exe C:/Users/Administrator/PycharmProjects/PythonStudy/test.py True False True
用isinstance判斷mongDB中的一些數據類型:blog
能夠引入types模板,獲取數據類型:ip
inport typesunicode
types取值:字符串
BooleanType
BufferType
BuiltinFunctionType
BuiltinMethodType
ClassType
CodeType
ComplexType
DictProxyType
DictType
DictionaryType
EllipsisType
FileType
FloatType
FrameType
FunctionType
GeneratorType
GetSetDescriptorType
InstanceType
IntType
LambdaType
ListType
LongType
MemberDescriptorType
MethodType
ModuleType
NoneType
NotImplementedType
ObjectType
SliceType
StringType
StringTypes
TracebackType
TupleType
TypeType
UnboundMethodType
UnicodeType
XRangeTypeio