Get Data Type in Python

Contrary to other programming languages, such as C++ or Java, you don’t specify the data type when defining a variable in Python, but it doesn’t mean that the variable doesn’t have a type.

You can check the variable type using the type function that returns the type of data.

Here’s how it works:

This code returns this result:

 <class 'int'>
 <class 'float'>
 <class 'float'>
 <class 'str'>
 <class 'str'>
 <class 'NoneType'>

You can also check types of data structures. Here’s an example of a list, dictionary, and tuple.

The result:

<class 'list'>
<class 'dict'>
<class 'tuple'>