This content originally appeared on DEV Community and was authored by All About Python
The first thing that kids aare taught as part of a structured curriculum is alphabets and numbers. They form the building blocks on top of which we build our understanding of the world. Similarly, to understand Python or any other programming language, we need to have clear understanding of its basic building blocks, the data types.
Data types refer to different ways in which python can store any data. Just like we can have names, home addresses, email IDs and many other such data pertaining to a person, we can have different types of data that we would need to work on in programming.
This blog post is meant to give absolute beginners a basic understanding of data types in python. In reality, there is still a lot to cover for many complex data types. But as a beginner, we don't need to worry about it for now. Let's start with understanding the different data types in python.
Data Types in Python
Data types in python are broadly classified into 5 types, depending on similarity.
- Numbers
- Sequences
- Sets
- Mappings
- None
Let's go through each of them one by one. We will be using interactive mode of python in this blog.
Numbers
As the name suggests, these are the data types that store numeric values, like integers, decimal numbers and complex numbers.
Integer
- All integer numbers fall into this data types
- Only integers fall into this category. If the number contains any decimal or an imaginary part (found in complex numbers) then it does not fall into integer data type
- Mathematical operations like addition, subtraction, multiplication or division can be performed on this data type
- The built in class for this data type is
int
(just remember the class associated with each integer for now).
>>> integer1 = 13212
>>> integer2 = -2938293
>>> integer3 = 0
- All the above variables are of integer data type. If you try to get their class using the
type
built-in function, you will getint
class.
>>> type(integer1)
<class 'int'>
Floating point
- All numeric values within python that has a decimal in it, falls into this data type
- This data type can be uniquely identified by a decimal sign, for example:
>>> thisisaninteger = 12
>>> thisisafloat = 12.0
- If I check their data types using the
type()
function, the first variable will haveinteger
data type and the second one will havefloat
data type - The built-in class name for float is
float
>>> float1 = 13212.0
>>> float2 = -2938293.234245234
>>> float3 = 0.0
>>> type(float1)
<class 'float'>
Complex
- All non-real or complex numbers fall into the category of complex data type
- This data type can be uniquely identified by j representing imaginary part of a complex number, for example:
>>> complex1 = 3-2j
>>> complex2 = -12-23j
- The built-in class name for complex data type is
complex
.
>>> complex1 = 3 + 2j
>>> complex2 = -3 -2j
>>> complex3 = -12j
>>> type(complex1)
<class 'complex'>
Boolean
- Boolean data type is a subset of integer data type.
- It has only two values,
True
andFalse
. - True represents non-zero, non-null, non-empty value while False represents zero, null or empty value.
- Note: True and False in python should be represented with T and F capital.
- The built-in class name for boolean is
bool
.
>>> boolean1 = True
>>> boolean2 = False
>>> type(boolean1)
<class 'bool'>
Sequences
- A sequence in python can be understood as an ordered collection of items, which can be indexed by an integer.
- There are three sequences in python:
- string
- lists
- tuples
String
- Is a collection of single characters
- Characters can be alphabets, digits, special characters or whitespaces
- String variables in python are declared using single quotes (‘) or double quotes (“), like this
>>> string1 = “Hello World”
- We cannot perform numeric operations on strings
- The built-in class name for string is
str
.
>>> string1 = “Hello World”
>>> string2 = “All About Python @ 123 !”
>>> type(string1)
<class 'str'>
List
- Is a sequence of items
- Items can be of any data type.
- List is always enclosed within square brackets [] and each item is separated by commas.
>>> list1 = [“item1”, “item2”, “item3”]
- The built-in class name for list is
list
.
>>> list1 = [“item1”, “item2”, “item3”]
>>> list2 = [1, 2, 3, “string”, True]
>>> type(list1)
<class 'list'>
Tuple
- Is a sequence of items, which cannot be changed.
- Items can be of any data type.
- Tuple is always enclosed within round brackets () and each item is separated by commas.
>>> tuple1 = (“item1”, “item2”, “item3”)
- The built-in class name for tuple is
tuple
.
>>> tuple1 = (“item1”, “item2”, “item3”)
>>> tuple2 = (1, 2, 3, “string”, True)
>>> type(tuple1)
<class 'list'>
Sets
The reason sets are different from other sequence data types is because unlike sequences, sets don't have any duplicates.
- Represents unordered sequence of items in python.
- Is enclosed with curly brackets {} and items are separated by comma.
- The built-in class name for sets is
set
.
>>> set1 = {1, 2, 3}
>>> set2 = {“All”, “About”, “Python”}
>>> type(set1)
<class 'set'>
None
- Signifies absence of data in python.
- It has only one value which is None.
>>> nothing = None
>>> type(nothing)
- The built-in class name for None is
NoneType
.
>>> type(None)
<class 'NoneType'>
Mappings
- These are the unordered data type containing data in the form of key value pair
- It has only one data type within it, called dictionary.
Dictionary
- Holds data in key value pair.
- Items can be of any data type.
- List is always enclosed within round brackets () and each item is separated by commas.
>>> dict1 = {“name”: “All About Python”, age: 20}
- The built-in class name for tuple is
tuple
.
>>> dict1 = {“name”: “All About Python”, age: 20}
>>> type(dict1)
<class 'dict'>
Homework Assignment: Storing Your Information
A little homework assignment for you all, try creating a list, tuple and set which stores the following values:
- Your full name
- Your age
- Your email ID And also try to create a dictionary with the same.
Conclusion
In this blog, we covered the basic data types in Python: numbers, sequences, sets, mappings, and None. Each type is used to store different kinds of data, and understanding these types is the first step in becoming a Python programmer.
In the next blog, we will dive deeper into functions in Python and why they are important.
This content originally appeared on DEV Community and was authored by All About Python

All About Python | Sciencx (2025-01-13T13:03:57+00:00) Decoding Python Data Types: The Building Blocks of Programming (Day 4 of 100 Days of Python). Retrieved from https://www.scien.cx/2025/01/13/decoding-python-data-types-the-building-blocks-of-programming-day-4-of-100-days-of-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.