HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

Python Data Types

In computer programming, data types specify the type of data that can be stored inside a variable.

Example
num=24
 Here, 24 (an integer) is assigned to the num variable. So the data type of num is of the int class.
              

Types of Data Types


Data Types Classes Description
Numeric int, float, complex Holds numeric values.
String str Holds sequence of characters.
Sequence list, tuple, range Holds collection of items.
Mapping dict Holds data in key-value pair form.
Boolean bool Holds either True or False.
Set set, frozenset Holds collection of unique items.

Since everything is an object in Python programming, data types are actually classes and variables are instances(object) of these classes.


Numeric Data Types


Example

num1 = 5
print(num1, 'is of type', type(num1))

num2 = 2.0
print(num2, 'is of type', type(num2))

num3 = 1+2j
print(num3, 'is of type', type(num3))


Output:

5 is of type 
2.0 is of type
(1+2j) is of type 
 

type() function to know which class a certain variable belongs to.