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')

posted on 2016-04-27 23:44  与非朋仔  阅读(454)  评论(0编辑  收藏  举报

导航