python type
type() 用于获取对象类型的。
type(object) -> the object's type
测试
class ClassTest:
# declare a integer type variable
var_int = 12
# declare a string type variable
var_str = 'monday'
# declare a tuple type variable
var_tup = (1, 2, 'mono')
# it will show the ClassTest as a 'type'
print('Type of ClassTest :', type(ClassTest))
ct = ClassTest
# it will show the ClassTest as a 'class'
print('Type of ct :', type(ct))
# it will print the type of var_int as 'int'
print('Type of var_int :', type(ct.var_int))
# it will print the type of var_str as 'str'
print('Type of var_str :', type(ct.var_str))
# it will print the type of var_tup as 'tuple'
print('Type of var_tup :', type(ct.var_tup))
功能
基本上 type() 用于测试目的。