Python note:For check type typechk.py

来源:互联网 发布:终结者2审判日 知乎 编辑:程序博客网 时间:2024/06/06 08:36

  函数displayNumType()接受一个数值参数,使用内建函数type()来确认数值的类型(或不是一个数值类型)。


#!/usr/bin/env pythonimport syssys.setrecursionlimit(1000000)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(99999999999L)displayNumType(98.6)displayNumType(-5.2+1.9j)displayNumType('xxx')


0 0