A data type is a set of values and a set of operations that can be performed on these values. Let's first look at Python data types in terms of just their values.
Built-in Data Types
Python has a set of built-in data types. Built-in means that they are readily available to use in the Python language, without having to get them from external sources. We will only be discussing the main built-in data types, but do know that more exist.There are two main categories of built-in data types: numeric types and container types. Numeric types are numbers, while container types are used to group values together.
Within the numeric types, we have int
, bool
, and float
.
Within the container types, we have another category called sequence types. Inside sequence types, we have list
, tuple
, and str
. And the other container types are dict
and set
.
Lastly, a type, which is not part of numeric or container types, is the None
type.
Numeric Types
int
The first numeric type is int
. It represents positive integers, negative integers, and 0.
123
-50
0
Other programming languages, may have a restricted range of values for integer types. For example, in Java, its int
type is restricted to around negative 2 billion to positive 2 billion. Values outside of this range are a different type, called a long
, in Java.
However, in Python the range for int
is unlimited, and only restricted by the computer's memory. Therefore, all integers, whether they be very large or very small, all have a type of int
. This is convenient for us because we don't have to deal with different integer types depending on the integer value.
bool
Within the int
type, we have the bool
type, which represents boolean values.
True
False
Its set of values are True and False. Note that True and False must start with capital letters. bool
is a subtype of int
, because under the hood, True is 1 and False is 0.
float
The last numeric type is float
. It represents numbers that have a decimal point.
3.14159
-0.287
6.0
Unlike int
, the range of possible float
values in Python is restricted. But the range is large enough that we don't need to worry about it.
Container Types - Sequence Types
Now let's look at the container types. There is a subcategory called sequence types within the container types.
Here we have a group of int
s and float
s that make up a sequence.

We call these values elements. The defining feature of a sequence is that it uses integer indices to order and access its elements. The singular form of indices is index. The indices of a sequence are pre-defined. They are always int
values that start from 0 and go up by 1.
list
The first sequence type is list
. It represents a list of values. Each element in the list
has a corresponding index. The defining feature of list
s is that after they are created, their elements can change. For example, we can add, replace, or delete elements.
To create a list
, we use a pair of square brackets.
[]
This code has a type of list
and represents an empty list
.
If we add an int
inside, this becomes a list
with one element.
[3]
To add more elements, we use a comma for separation and then write the next element.
[3, 5]
All container types, except for str
, can contain any combination of types as elements.
[3, 5, 7.2, True]
tuple
The second sequence type is tuple
. It represents a list of values, just like the list
type. Each element in the tuple has a corresponding index. The difference between a list
and a tuple
is that the elements of a tuple
cannot change after the tuple
is created.
To create a tuple
, we use a pair of parentheses.
()
This code has a type of tuple
and represents an empty tuple
. If we add an int
inside, this code no longer has a type of tuple
, and is instead an int
.
(2)
It represents an int
value wrapped in parentheses, like how we use parentheses in math. To make it a tuple
type, we have to add a comma.
(2,)
So this a special syntax for the one element case of a tuple that we have to keep mind.
If we create a tuple with more elements, we use commas as normal.
(2, 3.4, False)
str
The last sequence type is str
. str
is short for “string”, which means a sequence of text. Each character in a string has a corresponding index. Unlike other container types that can contain any type as elements, strings only ever have single characters as elements.
To create an str
, we use a pair of quotation marks. We can either use a pair of double quotes or a pair of single quotes.
""
''
Both of these have a type of str
and represent empty str
s.
In between the quotations, we can add any sort of text, which includes numbers, symbols, and spaces.
"avocado"
'python is cool!'
Other Container Types
dict
Now for the other container types. We first have the dict
type, which is short for "dictionary".

Unlike sequences which are indexed using pre-defined ints, dictionaries are indexed with any type. The index is called a key. And it corresponds to a value. This key-value pair is referred to as an item. Keys are how we access the values of the dictionary. Therefore, the keys we set must be unique.
Although dictionaries are not indexed using int
s, which have an inherent order, the items of the dictionary still preserve their order. For example, if we create a dictionary like this, then the item “apple”: 5
will always be first in the dictionary. This means that the order of the dictionary is a feature that we can rely on.
To create a dict
, we use a pair of curly braces.
{}
This has a type of dict
and represents an empty dict
.
A key-value pair is created by writing the key, a semi-colon to separate the key from the value, and then the value.
{"jam": 5}
The key-value pairs are separated with commas.
{"jam": 5, "egg": 3, "tea": 2}
set
The last container type is the set
type. A set
is a group of unique elements that do not have indices. Therefore, unlike the previous container types, we cannot access specific elements of the set. The elements in the set are unique so there will never be duplicate elements. Even if we add duplicate elements to the set, the actual set in memory will not have duplicates.
set
is the only container type that is unordered. This means that the order of the elements is not preserved. For example, if we create a set with elements in this order,

the next time we access the set
, we cannot guarantee that 1.5 will be the first value. This means that the order of elements is not a feature we should use or rely on for set
s.
To create a set
, we use a pair of curly braces, just like we do when creating a dict
. But if both dict
s and set
s use curly braces then what is the type of a pair of curly braces? The answer is that a pair of curly braces always has a type of dict
and represents an empty dict
. If we want to write an empty set
in our code, we use the set()
constructor function with no arguments.
set()
Let's go back to the curly brace notation. Once we add an element to the set
, the code now has type set
.
{"abc"}
What makes the code have type set instead of a dictionary is that the elements are single values and not key-value pairs. We can add more elements to the set and separate them with commas.
{"abc", -0.1, 35}
None
Lastly, we have the None
type. Its set of values is a single value called None
.
None
None
must be written with a capital N. The None
value is used to represent the absence of a value.