python 学习笔记3------概述3
1、python对象3个属性:身份(id()获取),类型(type()获取),值2、对象值的比较和对象身份的比较:前者就不说了,后者用is或is not,表示两个变量是否实质为同一个对象的引用。3、检查类型#!/usr/bin/env pythondef displayNumType(num):print num, 'is',if isinstance(num,
·
1、python对象3个属性:身份(id()获取),类型(type()获取),值
2、对象值的比较和对象身份的比较:前者就不说了,后者用is或is not,表示两个变量是否实质为同一个对象的引用。
3、检查类型
#!/usr/bin/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!!'
import types
def displayNumType2(num):
print num, 'is a number of type: ',
if type(num) == types.IntType:
print types.IntType
elif type(num) == types.StringType:
print types.StringType
elif type(num) == types.FloatType:
print types.FloatType
elif type(num) == types.ComplexType:
print types.ComplexType
elif type(num) == types.LongType:
print types.LongType
else:
print 'not a number at all!!'
displayNumType(-69)
displayNumType(9999999999999999999999L)
displayNumType(98.6)
displayNumType(-5.2+1.9j)
displayNumType('xxx')
print '==========================================='
displayNumType2(-69)
displayNumType2(9999999999999999999999L)
displayNumType2(98.6)
displayNumType2(-5.2+1.9j)
displayNumType2('xxx')
4、内建函数总结
更多推荐
已为社区贡献4条内容
所有评论(0)