isinstance()和__name__

时间:2015-04-06 15:28:22   收藏:0   阅读:257
 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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!