Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
  • Live Instructor-led Classes
  • Expert Education
  • 24*7 Support
  • Flexible Schedule

Python Datatypes overview

One of the most crucial part of learning any programming language is to understand how the data is stored and manipulated in that language. Python users are often inclined towards python because of its ease of use and various number of versatile features it provides. One of those features is dynamic typing.

In python, unlike statically typed languages like C or Java, there is no need to specifically declare the data type of the variable. In Dynamically Typed languages such as Python, the interpreter itself predicts the datatype of the variable based on the type of value assigned to that variable.

Watch this Python Datatype video

In C, the declaration of any variable might look like the following code block:

/* C code block */
int sum = 0
for (int i=0;i<10;i++)
sum += i;

The equivalent code for the above operation in Python would look like the following code block:

sum = 0
for i in range (10):
sum += i

As we can observe from the above example, in C, all the variables are explicitly declared with their respective datatypes while in Python, we have directly taken a variable and then just assigned a value to it rather than declaring the datatype of that variable as well. In Python the datatypes of the variables are dynamically inferred. You can assign any value to the variable and the Python interpreter will identify the datatype. You can also re-assign a different type of value to an already assigned variable, unlike in C or Java where if you have declared a variable integer and then assign a string value to it, you will get an error.


# Python code block
a = 10
a = ‘Intellipaat’

The equivalent code for the above operation in C would look like:

/* C code Block */
int a = 10;
a = ‘Intellipaat’; //fails

This type of flexibility that comes as a result of being dynamically typed language is one of the reasons that Python is considered to be easy and convenient to learn and use.

Standard Datatypes in Python

As the name suggests, Datatype is the classification of type of values that can be assigned to variables.  We have already seen that here in Python, we don’t need to declare a variable with explicitly mentioning the data type, but it’s still important to understand what are the different types of values that can be assigned to variables in Python. Based on the type of variable’s value, the datatype of that variable is inferred by the Python interpreter.

Python datatypes are categorized in two categories, that is:

  • Mutable Datatypes: The Datatypes where the value assigned to a variable can be changed.
  • Immutable Datatypes: The Datatypes where the value assigned to a variable cannot be changed.

Following diagram lists the datatypes that fall under the category of mutable datatype and immutable datatype.

Standard Datatypes in Python

Following are the above mentioned standard datatypes in python:

  • Numbers: The number datatype in Python are used to store numerical values. They are used to carry out the normal mathematical operations.
  • String: Strings Datatype in Python are used to store textual information. They are used to carry out operations to perform positional ordering among items.
  • List: Lists datatype in Python is the most generic Python Data type. Lists can consist of a collection of mixed data types, stored by relative positions.
  • Tuple: Tuples in Python are immutable datatype that can store mixed datatypes. They are basically a list that cannot be changed.
  • Sets: Sets in Python is a datatype that can be considered as an unordered collection of data without any duplicate items.
  • Dictionary: Dictionaries in Python can store multiple objects, but unlike Lists, in Dictionaries the objects are stored by key and not by the positions.

This brings us to the end of this module. The above-mentioned Datatypes will be discussed in detail in their respective separate modules. See you there!

Meanwhile you can take a look at Intellipaat’s Python course which also assist with its free interview questions.

Previous Next

Download Interview Questions asked by top MNCs in 2019?

"0 Responses on Python Datatypes"

Leave a Message

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

Sales Offer

Sign Up or Login to view the Free Python Datatypes.