Types of Data 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.
Type | Description | Value |
---|---|---|
bool | Boolean values | False True |
NoneType | Absence of Value | None |
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'''