Home » Tech Learning » Python » Python Data Types With Practical Examples

# Python Data Types With Practical Examples

Home » Tech Learning » Python » Python Data Types With Practical Examples

As we already saw python data types and it’s the definition, now we will see all data types with its practical example.

## 1. Numeric Data type:

We already knew the numeric data type used for storing numeric values, so let’s see an example of all 3 numeric data types as Integer, Float, and Complex. If you want to check which type of data type is in python you can use the type() function.

``````# Integer data type (# keyword is used to comment in python)
a = 10
print(a) # print value of a.
print(type(a)) #type() function will identify the datatype``````
``````# Float data type
a = 40.34
print(a)
print(type(a))``````
``````# Complex data type
a = 2+ 5j
print(a)
print(type(a))   ``````

## 2. Sequence type:

It is a collection of similar or different data types which include 3 more types like “String”, “List”, “Tuples”. Let’s see an example of all 3 data types:

``````#String data type
str = 'Hello world, welcome to the single quote of string'
str1 = "Hello world, welcome to double quote of string"
str2 = """Hello world, welcome to triple quote of string"""         ``````
``````# List data type [ ]
list = [12, "Hello" ,"World",48]
print(list)
print(type(list)) ``````
``````# Tuple data type ( )
tuple = ("Hello", "Welcome" , "Python")
print(tuple)
print(type(tuple)
``````

## 3. Set type:

As we already knew set is a collection of unordered data type which is mutable it means after creation it will be editable. Let’s see an example of the set type.

``````# Set data type { }
set1 = {'Alice',10,20,40,'welcome','python'} # Creating set with values
set4 = set() # Creating empty set
print(set1)
print(set4)``````

## 4. Mapping type:

Mapping type contains Dictionary data type which is represented as key: value pair form. it is enclosed with curly braces. You can access the value of a dictionary using the key directly and print it whenever it’s necessary. Let us see an example of dictionary data type

``````# Dictionary data type {key:value}
d = {1:"Tom",2:"Bob",3:"Alice"}
print(d)
{1: 'Tom', 2: 'Bob', 3: 'Alice'}
print(type(d))``````

## 5. Boolean type:

We already knew the definition of data type which represents True or False value based on the comparison. whenever you will compare two values then the expression is executed and it always returns the Boolean value which can be either True or False. Let us see an example of Boolean type

``````# Boolean data type
print(20>10)
print(40<60) print(10>20)``````