码迷,mamicode.com
首页 > 编程语言 > 详细

python type演示

时间:2014-12-26 18:54:26      阅读:242      评论:0      收藏:0      [点我收藏+]

标签: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演示

标签:python type

原文地址:http://itsoar.blog.51cto.com/8915220/1596263

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!