获取对象的信息之内置函数type()

获取对象的信息之内置函数type()

class MyClass(object):
    pass

mc = MyClass()
print(type(mc))#<class '__main__.MyClass'>
print(type(18))
print(type("abc"))

print(type(MyClass))
print(type(int))
print(type(str))

def do_sth():
    pass

print(type(do_sth))#<class 'function'>
print(type(print))#<class 'builtin_function_or_method'>

print(type(18)==int)
print(type('abc')==str)

# print(type(do_sth)==function)
# print(type(print)==builtin_function_or_method)

import types
print(type(do_sth)==types.FunctionType)
print(type(print)==types.BuiltinFunctionType)

posted @ 2020-04-07 15:04  不知云深处  阅读(199)  评论(0编辑  收藏  举报