Next / Previous / Contents / TCC Help System / NM Tech homepage

20.43. type(): Return a value's type

This function can be applied to any value. It returns a type object corresponding to the type of that value.

For built-in types, the type object is the same as the name of the type: int, str, list, and so on. To test whether a value x is some type T, you can use the predicate “type(x) is T”.

If you display a type object in conversational mode, it will look like “<type 'T'>”. Examples:

>>> type(i)
<type 'int'>
>>> type(i) is int
>>> type([2,4,8]) is list