Python Datatypes


Datatypes

https://youtu.be/z6pbGb0UNWI?si=KmIcEbJcWeCe7nqf

Based on the nature of data, we can divide the datatypes in Python into many categories. The following table provides the datatypes for each category.

CategoryDatatypes
Numericint, float, complex
Booleanbool
Sequencelist, tuple, range
Textstr
Mappingdict
Setfrozenset, set
Binarybytes, bytearray, memoryview
NoneNoneType

Examples

The following table gives Python examples, and the respective constructor function, for each of the datatypes.

The constructor function is used to explicitly specify the datatype when creating the value of that datatype.

DatatypeExampleBuiltin Function
intx = 14int()
floatx = 3.14float()
complextx = 3 + 4jcomplex()
strx = "Hello World"str()
listx = ["apple", "banana", "cherry"]list()
tuplex = ("apple", "banana", "cherry")tuple()
rangex = range(20)range()
dictx = {"name" : "apple", "quantity" : 20}dict()
setx = {"apple", "banana", "cherry"}set()
frozensetx = frozenset({"apple", "banana", "cherry"})frozenset()
boolx = Truebool()
bytesx = b"apple"bytes()
bytearrayx = bytearray(5)bytearray()
memoryviewx = memoryview(bytes(5))memoryview()
NoneTypex = None-