Types#

Checking Types using type#

We have seen that data in Python can be classified as belonging to a specific type, e.g.

  • 1 is an integer.

  • 5.2123 is a floating-point number.

  • "Tuesday" is a string.

We can check the type of a data value using the type function.

type(1)
int
type(5.2123)
float
type("Tuesday")
str

This also works for None:

type(None)
NoneType

And even for functions:

type(print)
builtin_function_or_method

Numeric data types#

integers and floating-point numbers are both examples of numeric data types. Python also has a built in complex data type that can be used for working with complex numbers. Complex numbers in python are written using j to denote the imaginary component:

5 + 3j
(5+3j)
type(5 + 3j)
complex

Boolean data#

The other simple data type we will be working with a lot is the bool type, which represents Boolean or “logical” data. Boolean data can take one of two values: True or False.

type(True)
bool
type(False)
bool