In this article, we will learn about Python data types. In Python, data types are used to define the type of a variable. There are different types of built-in data types available in Python programming language.
Python data types are used to store different types of data e.g. an employee’s name is stored as a string, salary is stored as a number and date of joining as a date type variable.
Data types are important in programming as based on the data type of variable it can hold values of different types.

Understanding built-in Python Data Types
The built-in data types of Python data types provide a wide variety of data types that can be used to create variables of different types.
Below is the list of Python built-in data types available by default in the Python programming language.
Text Data Type – str
Numeric Data Types – int, float, complex
Sequence Data Types – list, tuple, range
Mapping Data Type – dict
Set Data Types – set, frozenset
Boolean Data Type – bool
Binary Data Types – bytes, bytearray, memoryview
None Data Type – None
How to Set the Data Type in Python
In Python programming language the data type of the variable is set when you assign a value to the variable. Based on the type of value being assigned to the variable the data type is set for the variable.
Here is the source code to demonstrate how to set the type for Python data types
message = "Hello World!" var1 = 100 var2 = 100.0 var3 = True var4 = 2j var5 = range(6) var6 = ["Red", "Yellow", "Blue", "Purple"] print(type(message)) print(type(var1)) print(type(var2)) print(type(var3)) print(type(var4)) print(type(var5)) print(type(var6))
Below is the output of the above code
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'complex'>
<class 'range'>
<class 'list'>
As you can see from the above output that the data type of the variable is set as per the type of value assigned to the variable.
How to Set the Specific Data Type in Python
By default in Python programming language, the data type of the variable is set to the type of the value being assigned. But if you want to set the specific data type for the variable then you can do that by using the constructor functions.
Here is the source code to demonstrate the list of functions available in Python programming language to set the specific data type in Python for the variables.
var1 = str("Hello World") #For string var2 = int(20) #For integer var3 = float(21) #For float var4 = complex(1j) #For complex var5 = list(("apple", "banana", "cherry")) #For list var6 = tuple(("apple", "banana", "cherry")) #For tuple var7 = range(6) #For range var8 = dict(name="John", age=36) #For dict var9 = set(("apple", "banana", "cherry")) #For set var10 = frozenset(("apple", "banana", "cherry")) #For frozenset var11 = bool(5) #For boolean var12 = bytes(5) #For bytes var13 = bytearray(5) #For byte array var14 = memoryview(bytes(5)) #For memory view print(type(var1)) print(type(var2)) print(type(var3)) print(type(var4)) print(type(var5)) print(type(var6)) print(type(var7)) print(type(var8)) print(type(var9)) print(type(var10)) print(type(var11)) print(type(var12)) print(type(var13)) print(type(var14))
Below is the output of the above code
<class 'str'>
<class 'int'>
<class 'float'>
<class 'complex'>
<class 'list'>
<class 'tuple'>
<class 'range'>
<class 'dict'>
<class 'set'>
<class 'frozenset'>
<class 'bool'>
<class 'bytes'>
<class 'bytearray'>
<class 'memoryview'>
As you can see from the above output that the data type of the variable is set as per the specific type by the constructor function.
Summary
In this article, we learned about Python Data Types and Python built-in Data Types. We also explored how to perform various operations on Data Types in Python programming language.
Other articles to read about Python Data Types
Understanding Python Numeric Data Types
You can also check my series on Python for Beginners – Series: Python Tutorial – Learn Python Programming for Beginners
References – Python Documentation
Please provide your suggestions & feedback in the comments section below
Hope you found this article useful. Please support the Author

Hi, nice article, very well explained data types in Python