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

x=2.5

print(type(x))

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

Python Programming 0 Comments

How to install Python pip on Linux?

Python pip is a package management tool used to find, install, remove and list the packages from the Python Package Index (PyPI). In this article, we will discuss how to

Python Programming 0 Comments

Best 7 Python IDEs And Code Editors

A code editor basically used to write and edit code it is usually lightweight and considered good for learning and small projects. Once you start writing code for larger applications

Programming 0 Comments

Taking Input From Users In Python

Computer programs often need to interact with users to get some kind of data from them. Later this data is processed and output is displayed on the console. For example,

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply