标签:
1 # coding: utf-8 2 3 def displayNumType(num): 4 print num, ‘is‘, 5 if isinstance(num, (int, long, float, complex)): # 如果变量num的值为元组(int, long, float, complex)中的一个,则运行此if块 6 print ‘a number of type:‘, type(num).__name__ # 打印‘a number of type:‘, 变量num的类名 7 else: 8 print ‘not a number at all!!‘ 9 10 displayNumType(-69) 11 displayNumType(99999999999999999999999999999L) 12 displayNumType(98.6) 13 displayNumType(-5.2+1.9j) 14 displayNumType(‘xxx‘)
运行结果:
关于isinstance():
关于__name__:
标签:
原文地址:http://www.cnblogs.com/longlongsky/p/4395899.html