Python does not support methods or function overloads, so you have to make sure that you call the function or object you want. What exactly is stored in a name? Quite a lot, especially when this is a type of name. It is often useful to confirm the identity of the type object that is received. To achieve this, Python provides a built-in function, type (). Type () returns the types of any Python object object, not limited to the standard type. Let's look at several examples of using the type () built-in function to return multiple object types through the interactive interpreter:
1>>> Type ("')2<type'Str'>3>>>4>>> s ='XYZ'5>>>type (s)6<type'Str'>7>>>8>>> Type (100)9<type'int'>Ten>>> Type (0+0j) One<type'Complex'> A>>>type (0L) -<type'Long'> ->>> Type (0.0) the<type'float'> ->>> ->>>type ([]) -<type'List'> +>>>type (()) -<type'tuple'> +>>>type ({}) A<type'Dict'> at>>>type (type) -<type'type'> ->>> ->>>classFoo:Pass #New-style class - ... ->>> foo =Foo () in>>>classBar (object):Pass #New-style class - ... to>>> bar =Bar () +>>> ->>>type (Foo) the<type'Classobj'> *>>>type (foo) $<type'instance'>Panax Notoginseng>>>type (Bar) -<type'type'> the>>>type (BAR) +<class '__main__. Bar'>
Python2.2 unifies the types and classes, and if you are using an interpreter below Python2.2, you may see different output results.
1>>> Type ("')2<type'string'>3>>>type (0L)4<type'Long int'>5>>>type ({})6<type'Dictionary'>7>>>type (type)8<type'Builtin_function_or_method'>9>>>Ten>>> type (Foo)#assumes Foo created as in above One<type'class'> A>>> Type (foo)#assumes Foo instantiated also -<type'instance'>
Python built-in function type () and isinstance () Introduction