三种方法查看数字数据的类型:[1] isinstance 可读性更好 #! /usr/bin/env python '''typechk.py''' def displayNumType(num): print num, 'is', if isinstance(num, (int, long, float, complex)): print 'a number of type:', type(num).__name__ else: print 'not a number at all!' displayNumType(-69) displayNumType(99999999999999999999L) displayNumType(99999999999999999999) displayNumType(98.6) displayNumType(-5.2+1.9j) displayNumType('aaa') ####### # output ####### -69 is a number of type: int 99999999999999999999 is a number of type: long 99999999999999999999 is a number of type: long 98.6 is a number of type: float (-5.2+1.9j) is a number of type: complex aaa is not a number at all! #! /usr/bin 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交