Return true if the?object?argument is an instance of the?classinfo?argument, or of a (direct or indirect) subclass thereof. Also return true if?classinfo?is a type object (new-style class) and?object?is an object of that type or of a (direct or indirect) subclass thereof. If?object?is not a class instance or an object of the given type, the function always returns false. If?classinfo?is neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (other sequence types are not accepted). If?classinfo?is not a class, type, or tuple of classes, types, and such tuples, a?TypeError?exception is raised.
Changed in version 2.2: Support for a tuple of type information was added.
2016-07-07
isinstance函數的原型是:
isinstance(object,?classinfo)
Return true if the?object?argument is an instance of the?classinfo?argument, or of a (direct or indirect) subclass thereof. Also return true if?classinfo?is a type object (new-style class) and?object?is an object of that type or of a (direct or indirect) subclass thereof. If?object?is not a class instance or an object of the given type, the function always returns false. If?classinfo?is neither a class object nor a type object, it may be a tuple of class or type objects, or may recursively contain other such tuples (other sequence types are not accepted). If?classinfo?is not a class, type, or tuple of classes, types, and such tuples, a?TypeError?exception is raised.
Changed in version 2.2: Support for a tuple of type information was added.
其中的classinfo指的是某種類型,比如常用的unicode:?
isinstance(some_str, unicode)?
來判斷是否是unicode類型的字符。但是想要知道其他還有哪些類型,網上沒找到具體說明,后來還是自己在python安裝后,自帶的的英文manual中找到了:
5.4. Numeric Types —?int,?float,?long,?complex
5.6. Sequence Types —?str,?unicode,?list,?tuple,?bytearray,?buffer,?xrange
5.7. Set Types —?set,?frozenset
5.8. Mapping Types —?dict
這樣,才知道,關于想要判斷某個變量的類型,就可以去手冊里面找到對應的變量名,然后測試是否是該類型變量了。