isinstance使用方法

#!/usr/bin/python2.7
    def displayNumType(num):
    print num, 'is',
    if isinstance(num,(int, long, float, complex)):
            print 'a num of type:', type(num).__name__
    else:
            print 'not a  num at all'
displayNumType(-69)
displayNumType(99999999)
displayNumType(98.8)
displayNumType(-5.3+9.9j)
displayNumType('xxx')

原文地址:https://www.cnblogs.com/flintlovesam/p/5440958.html