Skip to content

type()

using type() to validate the data type of the data

Format

py
type(data_required_to_validate_its_type)

Returned results:

<class 'data_type'>

Since it will return results, so we have to combine the variable (store the returned value) or print directly to use it. It won't be able to work if use directly

Usage

type.py

py
print(type(1))

print(type(1.0))

print(type("Hello, World!"))

print(type(True))

print(type(None))

Results:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
<class 'NoneType'>