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) orprint directlyto use it. Itwon'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'>