What is Data Type | How to use Python Data Types?

Python-Data-Types
Credit: Canva

Overview – Python Data Types

Let’s get started with Data Types in Python with the use of practical examples in Python.

What’s Next? – Python Data Types

In this article, I’ll cover the concept of Python Data Types. From data types theory to practical examples for various types of data types, I’ll make a command on all.

Prerequisite: Introduction to Python variable

Table of Contents

Watch Video Explanation

What is Data Type?

A data type in Python is like an identifier which helps to identify which type of data or value is stored in a variable.

Example: int, float, str, etc.

What is Structure of Data Type?

A structure of data types comprises a summary table of data types classified under a systematic manner to guide what are the various data types in Python and how they come across different categories.

structure of Data Types

What is Nature of Data Type?

Since the data types are defined under major two categories – mutable or immutable. A nature of data type defines whether data types are mutable (can be changed) or immutable (cannot be changed).

nature of data types

How to check the data type of a value?

To check the type of data there is a function available in Python is type(). All we have to do is store the variable name inside the type() function and we will know what type of data is stored in the variable.

Example: 

				
					box = "Chips & Chocolates"
print(type(box))

#Output:
<class 'str'>

				
			

What are various Data Types in Python?

Let’s cover different Python data types with complete definition and example.

Integer: An int or integer is a whole number that can be positive or negative with unlimited length.

E.g., 10, -23, 124578963, etc.

				
					snacks_packets = 6
print(snacks_packets)

print(type(snacks_packets))

#output:
6
<class 'int'>
				
			

Float: A Float or  floating-point number is a number with a decimal that can be positive or negative.

E.g., 1.0, 15.5, -12.54, etc.

				
					Chips_price = 10.5
Chocolate_price = 15.5

print(Chips_price)
print(Chocolate_price)

print(type(Chips_price))
print(type(Chocolate_price))

#output:
10.5
15.5
<class 'float'>
<class 'float'>
				
			

Complex number: A Complex number is the combination of real part + imaginary part.

z=a+bj (where a+b both can be positive or negative).

E.g., 1+2j, 2j, -2-3j, etc.

				
					complex_number = 1+8j
print(complex_number)

print(type(complex_number))

#output:
(1+8j)
<class 'complex'>
				
			

Dictionary: A Dictionary is used to store data in key:value pairs. Data stored in ordered and do not allow duplicate data.

E.g., {‘Name’: ‘Deepak’, ‘Age’: ‘23′}

				
					snacks_data = {"box":"Chips & Chocolates", "snacks_packets":6, "Chips_price":10.5, 
               "Chocolate_price":15.5, "is_box_open": False}

print(snacks_data)

print(type(snacks_data))

#output:
{'box': 'Chips & Chocolates', 'snacks_packets': 6, 'Chips_price': 10.5, 'Chocolate_price': 15.5, 'is_box_open': False}
<class 'dict'>
				
			

Boolean: A Boolean holds two values True or False. It is used to evaluate an expression, and returns one of two values.

E.g., 100>50, 100==50, etc.

				
					is_box_open = False
print(is_box_open)

print(type(is_box_open))

#output:
False
<class 'bool'>
				
			

Set: A Set is the collection of unique items, which is unordered and can be changed.

E.g., {1, 2, 3}, {‘a’, ‘b’, ‘c’}, etc.

				
					set_data = {"Chips & Chocolates", 6, 10.5, 15.5, False}
print(set_data)

print(type(set_data))

#output:
{False, 'Chips & Chocolates', 6, 10.5, 15.5}
<class 'set'>

				
			

String: A String is a sequence of characters, stored within a single quote (‘ ’) or double quote (“ ”).

E.g., ‘Hello’, “World”, etc.

				
					box = "Chips & Chocolates"
_box = 'Chips AND Chocolates'

print(box)
print(_box)

print(type(box))
print(type(_box))

#output:
Chips & Chocolates
Chips AND Chocolates
<class 'str'>
<class 'str'>
				
			

Tuple: A Tuple is the collection of ordered elements, allows duplicate elements, and is immutable in nature.

E.g., (‘A’, ‘B’, ‘C’, ‘A’), (1, 2, 3, 2), etc.

				
					tuple_data = ("Chips & Chocolates", 6, 10.5, 15.5, False)
print(tuple_data)

print(type(tuple_data))

#output:
('Chips & Chocolates', 6, 10.5, 15.5, False)
<class 'tuple'>
				
			

List: A List is the collection of ordered elements, allows duplicate elements, and is mutable in nature.

E.g., [‘A’, ‘B’, ‘A’], [1, 1, 3], etc.

Learn more: Python Data Types

				
					List_data = ["Chips & Chocolates", 6, 10.5, 15.5, False]
print(List_data)

print(type(List_data))

#output:
['Chips & Chocolates', 6, 10.5, 15.5, False]
<class 'list'>
				
			

What’s Your Task?

Now it’s your time to get a command on Python Data Types! Let’s come along with me and crack down on this task!

Define Variable names:

  1. What’s your favorite Movie name?
  2. How many times have I watched that movie?
  3. Is the movie available on streaming platform?

Identify:

  1. Identity the data types of the values stored in the variables?

You can write your comment on the YouTube video: Lesson 3 – What is Python Data Type? | How to use Python Data Types? | Python Tutorial

Conclusion – Python Data Types

So did you explore various Python data types with examples? And what about checking the type of value? Did you know the price of snacks packets? This article comprised a concept of data type theory + practical examples. From mutable to immutable data types, we covered Python beginner data types with a complete full detailed video. It will help you to get deeper about the data type along with a quick look to easy & understandable real-life examples.

Recent Articles