Data Types in Python

0/5 No votes

Report this app


In programming, the data type is the classification of data items. In Python, it tells the interpreter how the programmer intended to use data. Different types of operations are possible with different data types.

In Python programming data types are actually classes and variables are the objects or instances of these classes. If you don’t know what are classes and objects and what exactly they do, still you can proceed. We will discuss them in detail in the coming tutorials.

The built-in data types in Python

Python has the following built-in or standard data types –

Numeric Types – int, float, complex

Boolean Type – bool

Binary Types – byte, bytearray, memoryview

Text Type – str

Sequence Types – list, tuple, range

Set Types- set, frozenset

Mapping Type – dict

Data type declaration in Python

The data type declaration in Python happens automatically when you assign a value to a variable. The equal to i.e. = is used as an assignment operator to assign a value to a variable.

For example –

x=5   # x is integer type variable

x=2.5 # here x is a float type variable

x="Hello World !" # x is a string type

Explicit data type declaration in Python

By using constructor functions you can explicitly declare a variable with a specific data type. Now see the example below –

x = float(2)

Here variable x is explicitly declared as float type. This will store a value of 2.0.

How to find the data type of a variable

As discussed earlier in python data type is automatically declared when a value is assigned to a variable. Python provides type() function using which you can find the data type of a variable.

Example of using type() in Python



This will print the data type of variable x you can see the output of this in the given image –

In a few coming articles, we will discuss all these data types and their usage in Python with some examples.

Leave a Reply

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