Types of Data in Python

Author
By Darío Rivera
Posted On in Python

In Python 3 all data types are classes. This is very reminiscent of other languages ​​like Dart or even JavaScript itself. In this post we will see the types of data that come incorporated with Python 3 and some examples of them.

In the following table you will see in the first column the class that represents the data type, followed by its description and the values ​​that this data type can have.

TypeDescriptionValue
bool Boolean valuesFalse True
NoneTypeAbsence of ValueNone
int Integer Numbers a number
float Floating point numbers decimal numbers
str Character strings a string

In the following examples we use type to see the specific data type in Python.

print(type(True))          # <class 'bool'>
print(type(None))          # <class 'NoneType'>
print(type(7))             # <class 'int'>
print(type(7.9))           # <class 'float'>
print(type('hello world')) # <class 'str'>

String Type

The string data type can be defined in Python with single or double quotes. There is really no difference between these two types of definition other than style since there is no interpolation as in other languages.

str1 = 'hello'
str2 = "world"

To print a multiline string can be done using the escape character or triple quotes. The following two examples are equivalent.

x = 'hello\n' \
    'world'
x = '''hello
world'''

Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.