Python Data Types

By | October 21, 2020
Python Data Types

In this tutorial, we will discuss all Data Types used in Python.

Python Data Types

Python is a pure object-oriented programming language, which means that it is made up of Class and Objects, that you will learn later on this tutorial. For now, just to understand, it is defined as that Class is a structure of data which store information. To use that information we use objects and objects are the instance of a class. As in Python, everything is made up of class and we use their objects for the specific operations.


The data type is one of the class presents in Python to use them we take variables (objects) as their instance.

In General, if we define a data type, it is a kind of data item as defined by the values it can take.

To find the data type of an object or variable in the Python use the type() function.




<class ‘int’>

There are 6 types of Data types in Python.

  • Numbers
  • String
  • List
  • Tuples
  • Dictionary
  • Sets

Python Numbers

All the digits whether it is real or imaginary, all comes in the Python number data-types.

There are 3 types of Numbers in Python Data types: int, float, and complex numbers.


Every integer whether it is negative or positive comes in int category but it does not contain any decimal value.


var = 10


<class ‘int’>


Every number which contains a decimal value even .0 is termed as the float.


<class 'float'>

Complex numbers

A number which has an additional imaginary (a+ib) number comes in the category of complex numbers.


<class 'int'>

Python String

Everything which is written in between double style inverted comma (“ ”) or single inverted comma (‘) is considered as the string. It does not matter whether it is a word or digit or a special character except backslash (\) ( it is used to escape the character present in the string).

The variable stores the given string in a sequential manner and use indexing to call the specific value present in that variable.

Indexing is a method which is used to call the sequentially stored data in an efficient manner. When Python store data in sequential order, it gives each value an index number starts with 0 so we can easily grab the specific value.

There is a lot more about string which you will learn in the upcoming tutorials.

Let’s understand the string with an example:

string_2= "This is a String"
print(srting_1[0]) # Here we are using indexing
print(string_2[0:6]) # Here we are using String slicing calling the string_2 values from 0 to 6



This is a String

This i

Python List

The list is an ordered collection of different data types which stored in sequential order. The string is mutable which means you can change the values present in a list. To assign a list we use square brackets and to separate the values we use a comma (,).

List store the values in sequential order so it uses indexing to call the specific value present inside the list. The indexing in the list start with 0 and end one less than the total number of values present in the list.

Let’s understand it with an example:

#Output [1, 2, 3, 4, 5, 6, ‘Hello’, ‘world’, True] 1 2 [1, 20, 3, 4, 5, 6, ‘Hello’, ‘world’, True]

Python Tuple

Like the Python list, Python tuple is also a collection of different data types which stores the value in the sequential order and use the index to grab the specific values present in the tuple. The only difference between the tuple and list is tuple are immutable and use parenthesis instead of square brackets. The immutability of tuple signifies that once the values assigned inside the tuple parenthesis cannot be altered using the assignment operator. e.g.

tuple_1= (1,2,3,"tuple_1","is", "here")
print(tuple_1[3]) # tuple indexing


(1, 2, 3, ‘tuple_1’, ‘is’, ‘here’)
<class ‘tuple’>

Python Dictionary

A Python dictionary is an unordered collection of different data types with keys and values pairs. The Python dictionary does not store the values in sequential order so we use keys to grab the corresponding values.

To store a dictionary in a variable we use {} curly braces and like Python list dictionaries are mutable.


dictionary = {"key1": "value1", "key2":"value2", "key3":"value3", "key4":"value4"}
dictionary["key4"] = 4 # dictionaries are mutable


{‘key1’: ‘value1’, ‘key2’: ‘value2’, ‘key3’: ‘value3’, ‘key4’: 4}

Python Sets

Python sets are an unordered collection of different or unique data-types and in the set, you can not assign two repetitive value, if you do so the set itself delete the other one. Sets do not use indexing.




{1, 2, 3, 4, 5, 6, 7}

In the above example, the set deletes all the repetitive 6 and show only one.

Python Data Conversion

In Python, you get the special function to change the data type of the variable explicitly. When you assign or declare a variable it automatically assigns a data type to the variable according to the assigned value, but with the help of some function, you can change the data type of the declared variable.

Here are the following conversions that can be performed in Python.

From integer to float

You can change an integer to a float using the float() function.




From float to integer using int() function




From a integer or float to string using str() function




From string to a float and integer using float() and int() functions







From a string to a list using list() function

say="Hello world"


[‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘ ‘, ‘w’, ‘o’, ‘r’, ‘l’, ‘d’]

Leave a Reply

Your email address will not be published. Required fields are marked *