isinstance使用方法

isinstance使用方法,第1张

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://outofmemory.cn/zaji/586145.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存