Menu Close

Python Data Types with Examples

Python Data Types with Examples

In this Python tutorial, we will see Python Data types with examples. To know the data types in Python, you must know the Python variables, and rules to create variables in Python.

➡️ Click here to learn all about the Python Variables.

Before going to see Python data types let’s brushup the Python Variables.

What are Python Variables?

Variables in Python are a kind of container that is used to store any kind of values for future use cases. As we know, Python is a dynamic-typed programming language which means we don’t need to specify the type of the variable before storing the value to a variable.

Here dynamically typed means, Python automatically detects the data type of the variable based on the value stored in a variable.

Let’s see a simple example.

name = "Programming Funda" # Data type of the name will be string.
name = 111 # Data type of the name will be int.

Let’s see how we can know the data type of the variables using Python’s built-in function.

What are Python Data Types?

Data types in Python mean type of the value that a variable can store. In the above example, the data type of the first name will be Sring and the data type of the second name will be int.

Data Types in Python with Examples

To check the data type in Python, Python provides a function called type(). The type() function returns the data type of the passed variable.

Here I have mentioned some common data types in Python with the help of the examples.

Numeric Type

Under Numaric there are three data types. int, float, and complex.

Let’s by an example.

age = 56
# int data types

value = 101.40
# float data type

complex_value = 10+10j
# complex data type


<class 'int'>
<class 'float'>
<class 'complex'>

String Type

The sequence of characters enclosed by single or double quotes belongs to the string data type.

name = "Programming Funda"
# string data type

The Output will be

<class 'str'>

Boolean Type

Only two values belong to a boolean data type which is True and False.

value_1 = True
value_2 = False
# bool data type


<class 'bool'>
<class 'bool'>

Sequence Type

Python list and Python tuple belong to sequence data type.

lst = [1, 2, 3, 4]
tpl = (1, 2, 3, 4)
# sequence data type


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

Mapping Type

Python Dictionary belongs to the mapping type because it stores data in the form of keys and values.

dct = {"name": "Programming Funda", "age": "4 Years"}
# dict data type


<class 'dict'>

Set Type

Python set belongs to the set data type. It is an unordered collection of unique items and it is a mutable data type also. Python set always creates, placing all the items inside curly braces {} separated by commas.

st = {"Programming Funda", 12}
# set data type


<class 'set'>

None Type

A variable with a None value indicates the null data type.

value = None
# null data type
<class 'NoneType'>

Python Useful Articles:


So, in this tutorial, we have seen all about data types in Python with examples. Python data types are important in real-life applications because sometimes you can decide based on data types of Python variable values.

Understanding variables and data types is fundamental in Python programming, as it allows you to effectively manipulate and work with different kinds of data within your programs.

If you found this article helpful, please share and keep visiting for further Python tutorials.

Thanks for your time…

How to Unlock the Power of PostgreSQL for XML Transformation
Python PIP Tutorial with Examples

Related Posts