菜比之路

走菜比的路,让大牛说去吧
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

【python】实例-判断用户输入数字的类型

Posted on 2015-01-14 14:54  毕加索的ma  阅读(804)  评论(0编辑  收藏  举报
num=input("please input the num: ")
print "the number your input is: "+str(num)
def checktype(num):
    if isinstance(num,(int,long,float,complex)):##isinstance 是判断是否是一个类的实例,如果是返回true
        print str(num)+" type is "+type(num).__name__
    else:
        print str(num)+" type is not sure"
checktype(num)