Python

P
PythonHub
Progress 0%

Python

  • Home
  • History of Python
  • Applications of Python
  • Introduction To Python
    • What is Python
    • Character Set
    • Tokens in Python
    • Python Execution Mode
    • Variable And Identifiers
    • Data Types in Python
    • Operators And Expressions
    • Constants in Python
    • Assignment Statement
    • Input / Output in Python
    • Simple Python Scripts
    • Namespace in Python
    • šŸ“ Assignments
  • Operators in Python
    • Arithmetic Operators
    • Assignment Operators
    • Shorthand Assignment Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Special Operators
    • šŸ“ Assignments
  • Input Output in Python
    • Accept Input
    • Output Formatting
    • šŸ“ Assignments
  • Conditional Statement
    • Decision Making
    • if Statement
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • Short Hand IF-ELSE
    • šŸ“ Assignments
  • Loops
    • Introduction to Loops
    • While Loop
    • Nested While Loop
    • šŸ“ While Loop Assignments
    • For Loop
    • For Loop Examples
    • Nested For Loop
    • Nested For Loop Examples
    • Infinite While Loops
    • Infinite For Loops
    • Break, Continue and Else in Loops
    • Difference Between For and While Loop
    • For Each Loop
    • šŸ“ For Each Assignments
    • šŸ“ All Loops Assignments
  • List
    • List in Python
    • Access List Elements
    • List Functions
    • Iterate (Loop) List
    • List Comprehension
    • šŸ“ Assignments
  • Tuple
    • Tuple in Python
    • Access Tuple Elements
    • Tuple Functions
    • Iterate (Loop) Tuple
    • Unpack Tuple
    • Tuple Comprehension
    • šŸ“ Assignments
  • Set
    • Set in Python
    • Access Set Elements
    • Set Methods
    • Iterate (Loop) Set
    • Pack/Unpack Set
    • Set Comprehension
    • šŸ“ Assignments
  • Dictionary
    • Dictionary
    • Access Dictionary Items
    • Dictionary Methods
    • Iterate (Loop) Dictionary
    • Formatting Dictionaries
    • Nested Dictionaries
    • Dictionary Comprehension
    • šŸ“ Assignments
  • Diff List Tuple Set Dictionary
    • List vs Tuple
    • List vs Set
    • List vs Dictionary
    • Tuple vs Set
    • Tuple vs Dictionary
    • Dictionary vs Set
    • šŸ“ Assignments
  • Exception
    • Error vs Exception
    • Exception Handling
    • Types of Exception
    • User Defined Exception
    • Logging Exception
    • šŸ“ Assignments
  • Functions
    • Introduction to Functions
    • Modular Programming
    • Types of Functions
    • Inbuilt Functions
    • Need For User-Defined Function
    • Elements of User Defined Function
    • Function Arguments
    • Nesting of Functions
    • Recursion
    • Global Local and Non Local
    • Python Lambda Functions
    • šŸ“ Assignments
  • Python Module
    • Introduction to Module
    • Inbuilt Modules in Python
    • User Defined Module
    • šŸ“ Assignments
  • File Handling
    • Introduction to Files
    • Create File
    • Read Files
    • Write to File
    • Rename File
    • Copy File
    • Move File
    • List Files in Directory
    • Binary Files
    • Zipping and Unzipping Files
    • šŸ“ Assignments
  • Strings
    • Basics of Strings
    • String Special Operators
    • String Formatting Operators
    • String Methods
    • šŸ“ Assignments
  • Regular Expressions
  • Python OOPS
    • Basics of Object Oriented
    • What are Classes and Objects?
    • Creating Class and Object
    • OOP vs Procedural Programming
    • Difference Between Classes and Objects
    • Constructors
    • Destructor
    • Built Class Methods and Attributes
    • Class and Instance Variables
    • Inheritance in Python
    • Single Inheritance
    • Multiple Inheritance
    • Multilevel Inheritance
    • Hierarchical Inheritance
    • Hybrid Inheritance
    • Abstraction
    • Method Overriding
    • Abstract Method
    • Interfaces in Python
    • Abstract Class vs Interface
    • Public, Private and Protected
    • Overloading vs Overriding
    • Inheritance vs Composition
    • Encapsulation
    • Polymorphism
    • Inner Classes
    • šŸ“ Assignments
  • Advanced Python
    • Iterator in Python
    • Generator in Python
    • Decorator in Python
    • Type Hints in Python
    • Async/Await Programming
    • Dataclasses in Python
    • Context Managers in Python
    • Property Decorator in Python
    • __slots__ in Python
    • Enums in Python
    • Walrus Operator in Python
    • Match-Case in Python
    • šŸ“ Assignments
  • Python Standard Library
    • Collections Module
    • Itertools Module
    • Functools Module
    • Datetime Module
    • JSON Module
    • OS Module
    • Sys Module
    • Random Module
    • Math Module
    • šŸ“ Assignments
  • Python Testing
    • Unit Testing in Python
    • Pytest Framework
    • Mocking in Python
    • šŸ“ Assignments
  • Python Best Practices
    • PEP 8 Style Guide
    • Docstrings in Python
    • Logging in Python
    • Code Optimization Tips
    • Debugging Techniques
    • šŸ“ Assignments
  • MySQL Database in Python
    • Introduction to MySQL with Python
    • DBMS vs File System
    • Connecting to MySQL Database
    • Create Database in MySQL
    • Create Table in MySQL
    • Insert Data in MySQL
    • Insert Multiple Rows
    • Select Data from MySQL
    • WHERE Clause in MySQL
    • Update Data in MySQL
    • Delete Data from MySQL
    • Parameterized Queries
    • Transaction Management
    • Error Handling
    • Connection Pooling
    • MySQL Drivers Guide
    • Joins in MySQL
    • Aggregation Functions
    • Backup MySQL Database
    • Best Practices
    • šŸ“ Assignments
  • MySQL Database Operations
    • SELECT Statement
    • MySQL Operators
    • DDL Statements
    • DML Statements
    • Subqueries
    • JOIN Operations
    • Aggregation
    • Case Study
    • šŸ“ Assignments
  • Graphics in Python
  • Threads in Python
    • Introduction to Threads
    • Process vs Threads
    • Concurrent Programming & GIL
    • Uses of Threads
    • Creating Threads
    • Single Tasking
    • Multi Tasking
    • Thread Synchronization
    • šŸ“ Assignments
  • Interview Questions & Answers
  • Python Case Studies
  • Multiple Choice Questions
  • šŸ“ Practice Problems
Get in Touch
  • tech2dsm@gmail.com

© Sankalan Data Tech

Python Language Interactive Tutorial

šŸ Python Data Types: Complete Guide with Examples

Python Data Types - Complete Guide

Understanding Python data types — the foundation of every Python program

Created by Sankalan Data Tech Team Verified
Data Engineers, Analysts, Scientists & Trainers
We are a team of Python developers, data engineers and data scientists with years of real-world experience. We have built production applications. We have tackled complex problems. We have helped teams ship better code. What drives us? Teaching — especially that moment when things finally click. Our tutorials focus on practical examples and honest guidance. Whether you are just starting out or leveling up we are here to make Python genuinely useful.
šŸ“‘ On this page:
  • What are Data Types?
  • Numeric Data Types
  • Sequence Data Types
  • Dictionary
  • Boolean
  • Set
  • Try It Yourself
  • Test Your Knowledge
  • FAQ
  • Learning Resources
Share this tutorial:
Twitter LinkedIn Facebook WhatsApp Reddit Telegram Email Copy Link
šŸ“š What You'll Learn Here
  • What are Data Types — Understanding how Python stores data
  • Numeric Data Types — Integers, floats, and complex numbers
  • Sequence Data Types — Strings, lists, and tuples
  • Dictionary — Key-value pairs for structured data
  • Boolean — True and False values
  • Set — Unordered collections of unique items
  • Hands-on Practice — Write and run Python code
  • Interactive Quiz — Test your knowledge

So, What Exactly Are Data Types?

In programming, a data type is a classification that specifies what kind of value a variable can hold and what operations can be performed on it. Think of it like a container — some containers hold numbers, others hold text, and some hold complex structures.

Python is a dynamically typed language, which means you don't need to declare the data type of a variable. Python automatically determines the type based on the value you assign.

# Python automatically detects data types
a = 25          # Python knows this is an integer
b = 3.14        # Python knows this is a float
c = "Python"    # Python knows this is a string

print(type(a))  # <class 'int'>
print(type(b))  # <class 'float'>
print(type(c))  # <class 'str'>

Python's built-in data types can be grouped into several categories:

šŸ”¢ Numeric

int, float, complex

šŸ“š Sequence

str, list, tuple

šŸ“– Dictionary

dict

⚔ Boolean

bool

šŸŽÆ Set

set

šŸ’” Fun fact: Everything in Python is an object, and data types in Python are actually classes. Variables are instances of these classes! That's why you can use methods like .upper() on strings.

1. Numeric Data Types

Numeric data types store numbers. Python has three numeric types:

a. Integer (int)

Integers are whole numbers — positive, negative, or zero — without any decimal point. Python integers have unlimited precision, meaning they can be as large as your memory allows.

a = 6
b = 456577
c = 6700000000000000000000000000000000000000000000000

print(type(a))  # <class 'int'>

b. Float (float)

Floats are numbers with a decimal point. They can represent real numbers and are written with a decimal point or using scientific notation.

g = 9.8
pi = 3.14159
temperature = -1.55

print(type(g))  # <class 'float'>

c. Complex (complex)

Complex numbers have a real part and an imaginary part. In Python, the imaginary part is denoted by j.

c = 1 + 2j  # complex number
print(type(c))  # <class 'complex'>
# Numeric Data Type Examples
a = 6       # int
print(a)
print(type(a))

g = 9.8     # float
print(g)
print(type(g))

c = 1 + 2j  # complex
print(c)
print(type(c))

Output:
6
<class 'int'>
9.8
<class 'float'>
(1+2j)
<class 'complex'>

2. Sequence Data Types

Sequence data types store collections of items in an ordered manner. Python has three sequence types:

a. String (str)

Strings are sequences of characters. They can be defined using single quotes, double quotes, or triple quotes.

s = "Welcome to Python"
print(s)        # Welcome to Python
print(type(s))  # <class 'str'>

b. List (list)

Lists are ordered, mutable collections that can hold items of different data types. They are defined using square brackets [].

my_list = [1, "two", 3.5]
print(my_list)      # [1, 'two', 3.5]
print(type(my_list)) # <class 'list'>

c. Tuple (tuple)

Tuples are ordered, immutable collections. Once created, they cannot be modified. They are defined using parentheses ().

my_tuple = (1, 2, "three")
print(my_tuple)      # (1, 2, 'three')
print(type(my_tuple)) # <class 'tuple'>

3. Dictionary

Dictionaries are unordered collections of key-value pairs. Each key is unique and is used to access its corresponding value.

my_dict = {"name": "Python", "age": 40}
print(my_dict)      # {'name': 'Python', 'age': 40}
print(type(my_dict)) # <class 'dict'>

4. Boolean

The Boolean data type represents one of two values: True or False. It's used in conditional statements and comparisons.

is_python_fun = True
print(is_python_fun)    # True
print(type(is_python_fun)) # <class 'bool'>

5. Set

Sets are unordered collections of unique elements. They are mutable and are defined using curly braces {}.

my_set = {"Python", "C", "CPP"}
print(my_set)       # {'Python', 'C', 'CPP'}
print(type(my_set))  # <class 'set'>

Try It Yourself!

Now it's your turn! Write and run Python code directly in your browser:

Loading Pyodide... 0%
Python Code Editor
========================================
NUMERIC DATA TYPES
========================================
Integer: 42 (type: int)
Float: 3.14159 (type: float)
Complex: (1+2j) (type: complex)

========================================
SEQUENCE DATA TYPES
========================================
String: Hello Python (type: str)
List: [1, 'two', 3.5] (type: list)
Tuple: (1, 2, 'three') (type: tuple)

========================================
DICTIONARY
========================================
Dictionary: {'name': 'Python', 'age': 40} (type: dict)

========================================
BOOLEAN
========================================
Boolean: True (type: bool)

========================================
SET
========================================
Set: {'Python', 'C', 'CPP'} (type: set)

āœ… Explore different data types!

šŸŽÆ Challenge Yourself!
• Create a variable with your favorite number and check its type
• Create a list of your favorite programming languages
• Create a dictionary with your name and age

šŸ†

šŸŽ‰ You've Mastered Python Data Types!

You now understand the fundamental data types in Python — numeric, sequence, dictionary, boolean, and set. These are the building blocks of every Python program!

Quick Quiz - Test Your Knowledge

Let's see what you've learned about Python data types:

1. Which data type is used for whole numbers in Python?
2. Which data type is immutable (cannot be changed after creation)?
3. What function is used to check the data type of a variable in Python?

Frequently Asked Questions

šŸ¤” What is the difference between a list and a tuple? ā–¼

Lists and tuples are both sequence data types, but lists are mutable (can be changed) while tuples are immutable (cannot be changed). Lists use square brackets [] and tuples use parentheses ().

šŸ’» Why is Python called a dynamically typed language? ā–¼

Python is dynamically typed because you don't need to declare the data type of a variable. The interpreter automatically detects the type based on the value assigned. This makes Python more flexible and easier to write, especially for beginners.

šŸŽÆ Can a variable change its data type in Python? ā–¼

Yes! Because Python is dynamically typed, a variable can change its data type at any time. For example, x = 10 creates an integer, but later x = "Hello" changes it to a string. This flexibility is one of Python's key features.

šŸ“š How do I check the data type of a variable? ā–¼

You can use the built-in type() function. For example, type(10) returns <class 'int'>. This is very useful for debugging and understanding what type of data you're working with.

šŸ“š Where to Go From Here

Now that you understand Python data types, here are some related topics to explore:

šŸ”£ Python Tokens

Learn about keywords, identifiers, and operators

šŸ”§ Operators

Learn about Python operators and expressions

šŸ“ Constants

Learn about constants in Python

šŸ“– Related Tutorials
  • What is Python
  • Tokens in Python
  • Variable and Identifiers
  • Applications of Python
Previous: Variable and Identifiers Next: Operators and Expressions →