Introduction

In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:

Types of Datatypes

TextString
Numericint,float,complex
Sequencelist,tuple,range
Mappingdict
Setset,frozenset
Booleanbool
Binarybytes,bytearray,memoryview
NonetypeNone

Getting the Datatype

You can get the data type of any object by using the type() function:

typeExampleGetting Typeoutput
inta = 100type(a)<class 'int'>
floata = 100.43type(a)<class 'float'>
complexa = 1jtype(a)<class 'complex'>
stra = "hello world"type(a)<class 'str'>
lista = [2,"hi"]type(a)<class 'list'>
tuplea = ("tuple",34.4)type(a)<class 'tuple'>
rangea = range(10)type(a)<class 'range'>
dicta = {1:"hello",2:"world"}type(a)<class 'dict'>
seta = {"hello",24,"world"}type(a)<class 'set'>
frozenseta = frozenset({"hello",12,4})type(a)<class 'frozenset'>
boola = Truetype(a)<class 'bool'>
bytesa = b'hello'type(a)<class 'bytes'>
bytesarraya = bytearray(10)type(a)<class 'bytearray'>
memoryviewa = memoryview(bytes(10))type(a)<class 'memoryview'>
NoneTypea = Nonetype(a)<class 'NoneType'>

Setting the Datatype

If you want to specify the data type, you can use the following constructor functions

typeExampleGetting Typeoutput
inta = int(100)type(a)<class 'int'>
floata = float(100.43)type(a)<class 'float'>
complexa = complex(1j)type(a)<class 'complex'>
stra = str("hello world")type(a)<class 'str'>
lista = list((2,"hi"))type(a)<class 'list'>
tuplea = tuple(("tuple",34.4))type(a)<class 'tuple'>
rangea = range(10)type(a)<class 'range'>
dicta = dict(1="hello",2="world")type(a)<class 'dict'>
seta = set(("hello",24,"world"))type(a)<class 'set'>
frozenseta = frozenset(("hello",12,4))type(a)<class 'frozenset'>
boola = bool(0)type(a)<class 'bool'>
bytesa = bytes(10)type(a)<class 'bytes'>
bytesarraya = bytearray(10)type(a)<class 'bytearray'>
memoryviewa = memoryview(bytes(10))type(a)<class 'memoryview'>