Python Data Types
Data Types
The concept of data types is extremely important, and mastering the differences and uses of each type offers valuable insight in to Python.
Generally, variables store data types. In some programming languages, each specific data type has to be declared in order to operate. In Python, this rule does not apply and the type of data automatically appoints itself when variables assign values.
The following are the built-in by default data types in Python.
- Text: string (str)
- Numbers: integer (int), float, complex
- Sequence: list, tuple, range
- Set: set, frozenset
- Mapping: dictionary (dict)
- Boolean: boolean (bool)
- None: NoneType
- Binary: bytes, bytearray, memoryview
This page will focus on the most commonly used data types in Python. These types are strings, numbers, as well as the four built-in data types used for storage: lists, tuples, sets, and dictionaries.

String (str)
Strings refer to text, and Python determines them through the use of either single or double quotes.
# String is assigned to a variable "x" and then displayed through the function "print" x = "This is a text" print(x) # String is displayed directly through the function "print" print("This is another text")
In order to apply multiple lines of text, Python uses three single or double quotations. The following is an example of multiple lines.
x = '''This is a multi-line text. and it continues on the second line as well. The third line also extends the text, and it finally ends on the forth line.''' y = """Another example of multi-line text. This instance has only three lines."""
When printed with the function “print”, the outcome will display “x” the same way as it is in the Python code, four lines. The same applies to “y”.
Numbers
Python uses three number types: integers, floats, and complex. All numbers can be positive or negative.
Integers refer to whole numbers, floats refer to decimals, and complex refer to the combination of real numbers and an imaginary number.
Below is an example of all three types of numbers.
# Integer x = 7 # Float y = 13.4 # Complex. The letter "j" is the imaginary number. z = 9 + 2j
Python automatically assigns the correct number type. But numbers can also be converted (through casting) with the keywords “int“, “float“, and “complex“.
# Integer to float x = float(14) print(x) # The output will produce the number 14.0
Data storage types
In Python, there are four built-in data types, having the purpose of storing multiple items in a single variable. Just other data types, Python does not need to declare the type. Instead, the programming language recognises them through the use of various brackets.
In addition, each data collection type has different features (used for different purposes).
The following characteristics determines the purpose of each data type.
- Mutable refers to whether the items in the data type can change.
- Ordered refers to whether the items in the data type have order.
- Indexing refers to whether the items in the data type have indexes (position numbers).
- Duplication refers to whether the items in the data type can have the same values as other items.
Lists
Lists store multiple items. They are the most flexible in comparison to the rest of data types for storing multiple items.
The data type lists are ordered, mutable, indexed, and duplicate allowable. This means each item in a list can change, has order, has index, and can have the same value as another item.
The declaration of lists is square brackets “[ ]” and items are separated by commas.
# List someList = ["red", "blue," "green"] # Displays the list print(someList)
Tuples
Tuples are ordered, immutable, indexed, and duplicate allowable. This means each item in a tuple cannot change, has order, has index, and can have the same value as another item.
The declaration of tuples is round brackets “( )” and items are separated by commas.
# Tuple someTuple = ("mouse", "keyboard", "speakers") # Display the tuple print(someTuple)
Sets
Sets are unordered, mutable, unindexed, and duplicate prohibited. This means each item in a set can change, has no order, has no index, and cannot have the same value as another item.
The declaration of sets is curly brackets “{ }” and items are separated by commas.
# Set someSet = {"tomatoes", "cucumbers", "spinach"} # Display the set print(someSet)
Dictionaries
Dictionaries are ordered, mutable, indexed*, and duplicate prohibited. This means each item in a dictionary can change, has order, has index*, and cannot have the same value as another item.
* Indexing in dictionaries differ from other data types, as they have keys and value pairs. As such, indexing works through the search of keys (similar to having index numbers).
The declaration of dictionaries is curly brackets “{ }” and items (keys and values) are separated by commas. Colons separate the keys and values.
# Dictionary (keys represent countries and values represent their capitals) someDict = { "UK": "London", "DE": "Berlin", "ES": "Madrid" } # The layout above is very common, as it improves readability.
Summary of characteristics

Python automatically declares data types. But we can also specify these types with the keywords “list()“, “tuple()“, “set()“, and “dict()“.
list(("red", "blue," "green")) tuple(("mouse", "keyboard", "speakers")) set(("tomatoes", "cucumbers", "spinach")) dict((UK = "London", DE = "Berlin", ES = "Madrid"))
Other data types
The following are the rest of the built-in data types in Python
- Boolean values represent one of two choices, True or False.
- NoneType refers to none, which indicates no value to return.
- Binary data types manipulate binary data.
# boolean x = True y = False # NoneType x = None # byte x = b"This is binary" # bytearray x = bytearray(7) # memoryview x = memoryview(byte(9))
Check data type
In Python, the keyword “type()” checks the type of data. Below is an example of type checking.
x = 3.7 type(x) # The output will produce "class float"
Next: Python Conditions