Python Built-in Data Types with Examples

Python has the following built-in data types. The following table provides the definition, name in Python, examples, and how to set data types. You can also click links to see in-depth explanations and examples.

Data TypesNames in PythonExamplesSet Data Types
Textstr“Hello World”str(“Hello World”)
Numericint12int(12)
float12.5float(12.5)
complex2kcomplex(2k)
Sequencelist[‘Tesla’,’Toyato’,’Ford’]list([‘Tesla’,’Toyato’,’Ford’])
tuple(‘Tesla’,’Toyato’,’Ford’)tuple((‘Tesla’,’Toyato’,’Ford’))
rangerange(3)range(3)
Mappingdict{‘brand’:’Tesla’,’year’:2021}dict(brand=’Tesla’,year=2021)
Setset{“Tesla”,”Toyato”,”Ford”}set({“Tesla”,”Toyato”,”Ford”})
frozensetfrozenset({‘brand’:’Tesla’,’year’:2021})frozenset({‘brand’:’Tesla’,’year’:2021})
BooleanboolTruebool(2)
Binarybytesb’hello world’bytes(“hello world”,’utf-8′)
bytearraybytearray(b’hello world’)bytearray(“hello world”,”utf-8″)
memoryview<memory at 0x000001F1EDBD4700>memoryview(bytes(“hello world”,”utf-8″))

How you can define a Dictionary in Python

I have provided separate posts for almost all the data types mentioned above in the table, even for dictionaries. However, I think it is necessary to provide additional examples here for dictionaries. As we can see below, there are 2 different ways of defining a dictionary, one using brackets and the one using dict(). Note that, the syntax is slightly different between them.

dictionary_1={'brand':'Tesla','year':2021}
print(dictionary_1)
dictionary_2=dict(brand='Tesla',year=2021)
print(dictionary_2)

The following is the output.

{'brand': 'Tesla', 'year': 2021}
{'brand': 'Tesla', 'year': 2021}