Data Types in Python

Data Types in Python


This post was last updated on February 2nd, 2021 at 07:54 pm

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.

Previous Variables and Constants In Python
Next Python Numeric Data Types

About author

You might also like

Programming 0 Comments

Introduction to Python functions

This post was last updated on March 6th, 2021 at 08:20 amA Python function is a self-contained module of code that performs a specific task. It takes inputs, processes them,

Python Programming 0 Comments

Python Indentation

An indentation or indent is an empty space at the beginning of a line that signals the start of a new logical block in a Python program. Many programming languages

Programming 0 Comments

Python Tuple Data Type

Python tuple data type is similar to the Python list in various ways. Like lists, you can use tuples to store different types of data. The only thing that differs


No Comments Yet!

You can be first to comment this post!

Leave a Reply