Python Data Types

Like any other Programming language, Python Programming language also provides Data Types which are used to classify a single type of particular data. Data Types are very important because the specific Data Type will determine what values are needed to be assigned to it and what operations one can perform for that operation.

 

Types of Data Types in Python

There are total of 6 number of Data Types in Python. They are given below:-

  1. Numbers

  2. String

  3. List

  4. Tuple

  5. Dictionary

  6. Set

 

Now we will discuss about all the Data Types in Python one by one with the help of suitable examples.

 

Number Data Type

Integers, Floating point and complex numbers falls under the category of Number Data Type in Python Programming Language. All these number data types are written in the form of (int stands for integer, float stands for floating point and complex stands for complex numbers). 

Integer Data Type

Now we will take a look on the example of Integer Data Type:-

 

a = 5

print(a, "is of type", type(a))

 

 

Output

5 is of type

 

As you can see that we had printed the type of data type and we found that it is of integer data type.

 

Floating Point Data Type

Now we will take example of floating point data type:-

a = 5.4

print(a, "is of type", type(a))

 

 

OUTPUT

5.4 is of type

As it is mentioned in the output that this is a floating point number as it is in decimal form. 

 

 

Complex Number Data Type

We will understand about complex numbers with the help of an example:-

a = 5 + 2j

print(a, "is of type", type(a))

 

 

OUTPUT

(5+2j) is of type

So you can see that when we entered a complex number we get its type as complex data type and it is always written in the form of a+bj.

 

Strings

Sequence of unicode characters is known as String and string is always written in single quotation or in double quotation marks. A string is denoted by str.

Let's take an example of String in Python:-

a = "Hello Coders"

print(type(a))

 

 

 

OUTPUT

 

As you can see we had printed the type of our data type which is of str type.

Python String examples Python String Examples

 

Lists

The data type which is used to store multiple items in a single variable is known as lists. These are ordered sequence of items. List is a built-in data type. The most important fact about list is that it is always written in square brackets[ ]. Lists are Mutable in nature.

Let's understand about list with the help of an example:-

 

a = [10, 20, 30, 40, 50]

print(a)

 

 

Python List create, append, remove element examples Python String Examples

 

OUTPUT

[10, 20, 30, 40, 50]

So our list has been printed.

 

 

Tuple

Just like lists, Tuple are also ordered sequence of similar items but Tuples are Immutable in nature. Tuples is also a built-in data type. We cannot modify tuple once it is created and it is always written in parenthesis(). 

Let's take an example of Tuple to understand it better:-

 

a = (10, 20, 30, 40, 50)

print(a)

 

 

OUTPUT

(10, 20, 30, 40, 50)

So you can see that a tuple is printed.

 

 

Dictionary

Dictionary is different from both list and tuple as it is unordered collection of key-value pairs and is always written in key:value pair. It is also a built-in data type. These are used for retrieving data. A dictionary is always represented with curly brackets{ }.

Let's take an example of Dictionary:-

 

a = {1:"Rohan", 2:"Sumit", 3:"Karan", 4:"Aman"}

print(a)

 

 

OUTPUT

{1: 'Rohan', 2: 'Sumit', 3: 'Karan', 4: 'Aman'}

So you can see that we had obtained a dictionary.

 

Python Dictionary add, delete example Python String Examples

 

Set

The data type which is used to store multiple items in a single variable are known as sets. It is a data type which is used to store data. It is a collection which is both unordered and unindexed. Set is also denoted within Curly brackets{}.

 

s = set([1, 2, 3, 4, 5])

print(s)

 

 

OUTPUT

{1, 2, 3, 4, 5}

So you can see that we had created a set first and then we had added a certain data which is printed within curly brackets as our final output.

More Tutorials