标签:类型 print nbsp pytho 复数 浮点型 数字 color 子类
Number数字类型支持: int (整数) float (浮点型) bool(布尔型) complex (复数)
内置的 type() 可以识别变量所指的对象类型:
a, b, c, d = 10, 55.4, false, 4+3j
print( type(a) ,type(b), type(c), type(d))
# 输出的结果是: <class ‘int‘> <class ‘float‘> <class ‘bool‘> <class ‘complex‘>
此外还可以用 isinstance 来判断:
a = 20.3
print( isinstance(a, float) )
# 输出结果是Ture
type 与 isinstance 区别就是:
在2中没有bool 类型,用1代表True,0代表False ! 而在3中True 与 False被定义成了关键字,值还是一样可以和数字进行计算
标签:类型 print nbsp pytho 复数 浮点型 数字 color 子类
原文地址:http://www.cnblogs.com/tenro/p/7662946.html