首页 > 代码库 > python type演示

python type演示

理论就不讲了,我感觉只有亲自敲代码,才能感觉到代码的神奇。


代码:

#!/usr/pin/env python

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(68)

displayNumType(23.1)

displayNumType(‘xxx‘)

displayNumType(99999999999999L)

displayNumType(-1.2+1.4j)


输出结果:

68 is a number of type: int

23.1 is a number of type: float

xxx is not a number at all!

99999999999999 is a number of type: long

(-1.2+1.4j) is a number of type: complex

python type演示