Python Datatypes

Built-in Data Types

In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

Python has the following data types built-in by default, in these categories:

Getting the Data Type

You can get the data type of any object by using the type() function:


Print the data type of the variable x:

x = 5


Setting the Data Type

In Python, the data type is set when you assign a value to a variable:

Setting the Specific Data Type

If you want to specify the data type, you can use the following constructor functions:

Test Yourself With Exercises


The following code example would print the data type of x, what data type would that be?

Start the Exercise

Python Data Types

Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.Following are the standard or built-in data type of Python:  




In Python, numeric data type represent the data which has numeric value. Numeric value can be integer, floating number or even complex numbers. These values are defined as int, float and complex class in Python.  

Note – type() function is used to determine the type of data type. 

 # Python program to
# demonstrate numeric value
a =5
print("Type of a: ", type(a))
b =5.0
print("\nType of b: ", type(b))
c =2+4j
print("\nType of c: ", type(c))


 Type of a:  <class 'int'>

Type of b:  <class 'float'>

Type of c:  <class 'complex'>


In Python, sequence is the ordered collection of similar or different data types. Sequences allows to store multiple values in an organized and efficient fashion. There are several sequence types in Python –  


In Python, Strings are arrays of bytes representing Unicode characters. A string is a collection of one or more characters put in a single quote, double-quote or triple quote. In python there is no character data type, a character is a string of length one. It is represented by str class.   

For more, checkout W3Schools and Geeks For Geeks.