University of Arizona, Department of Computer Science

CSc 120: Python type checking

You can use the type() function as a simple way to check the type of a variable or value:
Type of xTest for type of x
integer value type(x) == int
floating-point value type(x) == float
list type(x) == list
dictionary type(x) == dict
tuple type(x) == tuple

There are more general ways of doing this, but they are also more complex and involve concepts we have not yet covered. For now, the type() function is enough for our needs.