Top 7 Python Data Types: Examples, Differences, and Best Practices (2025)

By Rohit Sharma

Updated on Oct 15, 2025 | 26 min read | 101.6K+ views

Share:

Latest update: In March 2025, Pydantic, the go-to Python library for data validation, released version 2.11. This update supercharges speed and slashes memory use when working with Python data types. 

That means your data-heavy apps and APIs run smoother and faster than ever before!

Python data types define how data is stored, accessed, and manipulated in your programs. They form the base of every Python operation, whether you’re processing text, performing calculations, or managing complex data structures. Understanding them helps you write faster, cleaner, and more reliable code. In 2025, mastering Python’s built-in data types is still one of the most important skills for any developer. 

In this guide, you'll read more about the seven main data types in Python; integers, floats, strings, lists, tuples, dictionaries, and sets. You'll also explore the difference between mutable and immutable data types, learn how they impact performance, and discover best practices for choosing the right type in real-world projects. 

Improve your coding skills with upGrad’s Online Software Engineering Course. Specialize in cybersecurity, full-stack development, and much more. Take the next step in your learning journey!   

Understanding Python Data Types: The Foundation of Your Code 

So, what exactly are python data types? In simple terms, a data type is a classification that tells the computer how to interpret a value. It defines what kind of operations can be performed on the data and how it is stored in memory. When you write age = 30, Python automatically recognizes that 30 is a whole number and assigns it the integer data type. This is a feature called dynamic typing, where you don't have to explicitly declare the data type of a variable. Python figures it out for you. 

This might seem like a small detail, but it’s the bedrock of your entire program. The data type of a variable determines everything about it: 

  • The values it can hold: An integer type can hold 5, but not "hello". 
  • The operations it supports: You can perform mathematical addition on two numbers (5 + 10), but trying to do the same with a number and a text snippet might cause an error. 
  • The memory it consumes: Different data types require different amounts of memory to store their values. 

Choosing the correct data type is not just about avoiding errors; it's about writing clean, efficient, and readable code. Using the right type makes your intentions clear to anyone else reading your code (including your future self!). Python's rich set of built-in data types provides the flexibility to handle virtually any kind of information, from simple numbers to complex data structures. These types can be broadly grouped into categories like numeric, text, sequence, mapping, and set types, which we will explore next. 

Also Read: Variables and Data Types in Python [An Ultimate Guide for Developers] 

Numeric and Text Types: The Building Blocks 

At the core of almost every program are numbers and text. These are the most basic units of information you'll work with. Python provides simple and powerful types for handling them: Integers, Floats, and Strings. Let's look at each one. 

1. Integers (int) 

An integer is a whole number, without any decimal point. It can be positive, negative, or zero. Integers are perfect for counting things. 

  • Examples: 10, -77, 0, 123456 
  • When to use them: Use integers for anything that involves counting discrete items, such as the number of users, a loop counter, or an item's ID in a database. 
Python 
# Example of an integer 
user_count = 150 
print(user_count) 
print(type(user_count)) # Output: <class 'int'> 
 

Also Read: How to Take Multiple Inputs in Python: Techniques and Best Practices 

2. Floats (float) 

A float, or "floating-point number," is a number that has a decimal point. They are used to represent real numbers and are essential for calculations that require precision. 

  • Examples: 3.14, -0.001, 2.5, 1.5e2 (which is 1.5 * 10^2, or 150.0) 
  • When to use them: Use floats for scientific calculations, financial data like prices or interest rates, measurements (like height or weight), or any value that is not a whole number. 
Python 
# Example of a float 
price = 99.99 
print(price) 
print(type(price)) # Output: <class 'float'> 
 

Also Read: Float in Python: A Step by Step Guide 

3. Strings (str) 

A string is a sequence of characters used to store text. In Python, you can create a string by enclosing text in either single quotes ('...') or double quotes ("..."). Strings are one of the fundamental immutable data types in python, meaning they cannot be changed once created. 

  • Examples: "Hello, World!", 'Python 3.9', "upGrad", '12345' 
  • When to use them: Use strings for storing any kind of text, such as names, addresses, messages, file paths, or even numbers that won't be used in mathematical calculations (like phone numbers). 
Python 
# Example of a string 
user_name = "Alex" 
print(user_name) 
print(type(user_name)) # Output: <class 'str'> 
 

Also Read: A Beginner’s Guide to String Formatting in Python for Clean Code 

Data Science Courses to upskill

Explore Data Science Courses for Career Progression

background

Liverpool John Moores University

MS in Data Science

Double Credentials

Master's Degree17 Months

Placement Assistance

Certification6 Months

Here is a quick summary of these basic python data types

Data Type  Description  Example  Mutable? 
int  Whole numbers  42, -100  Immutable 
float  Numbers with a decimal point  3.14159, -9.8  Immutable 
str  Sequence of characters  "hello", 'data'  Immutable 

Sequence Types: Ordered Collections 

Sometimes you need to store more than just one value. You might need a collection of items, and often, the order of those items matters. Python's sequence types—Lists and Tuples—are perfect for this. They allow you to store an ordered collection of elements. 

1. Lists (list) 

A list is a versatile, ordered collection of items enclosed in square brackets []. Lists are one of the most commonly used data types in python because of their flexibility. They are also one of the core mutable data types in python, which means you can change their content—add, remove, or modify elements—after they have been created. 

Key Characteristics: 

  • Ordered: Items maintain a specific order. [1, 2, 3] is different from [3, 2, 1]. 
  • Mutable: You can change the list. You can add new items, delete existing ones, or change an item at a specific position. 
  • Allows Duplicates: A list can contain the same item multiple times. 
  • Can Contain Mixed Types: A single list can hold integers, strings, and even other lists. 

When to use them: Use a list whenever you need a collection of items that might need to change over time. Examples include a list of tasks in a to-do app, a list of students in a class, or a series of steps in a recipe. 

Python 
# Example of a list 
fruits = ["apple", "banana", "cherry"] 
print(fruits) 
 
# Modifying the list (since it's mutable) 
fruits.append("orange") # Add an item 
fruits[0] = "strawberry" # Change an item 
print(fruits) # Output: ['strawberry', 'banana', 'cherry', 'orange'] 
 

Also Read: A Complete Guide to Python List Comprehension with Practical Examples 

2. Tuples (tuple) 

A tuple is similar to a list—it's also an ordered collection of items. The key difference is that tuples are immutable. Once you create a tuple, you cannot change its contents. Tuples are defined using parentheses (). This immutability makes them predictable and slightly faster than lists. 

Key Characteristics: 

  • Ordered: Like lists, items in a tuple maintain their order. 
  • Immutable: You cannot add, remove, or change items after the tuple is created. This is a defining feature of immutable data types in python
  • Allows Duplicates: Tuples can contain duplicate values. 
  • Can Contain Mixed Types: A tuple can hold different data types. 

When to use them: Use a tuple for data that you know should not change. This provides a form of data integrity. Good examples include coordinates (x, y), RGB color values (255, 0, 0), or configuration settings that should remain constant throughout the program. 

Python 
# Example of a tuple 
coordinates = (10.0, 20.0) 
print(coordinates) 
 
# Trying to change a tuple will result in an error 
# coordinates[0] = 15.0  # This line would raise a TypeError 
 

Also Read: Learn About Python Tuples Function [With Examples] 

List vs. Tuple: A Quick Comparison 

Feature  List (list)  Tuple (tuple) 
Syntax  [1, 2, 3]  (1, 2, 3) 
Mutability  Mutable (Changeable)  Immutable (Unchangeable) 
Performance  Slightly slower  Slightly faster 
Use Case  For collections that need to be modified  For fixed collections of data 

Unordered and Mapping Types: Unique Structures 

Beyond simple ordered sequences, Python offers powerful data types for handling collections of unique items and for mapping relationships between data. Sets and Dictionaries provide fast and efficient ways to manage more complex data structures. 

1. Sets (set) 

A set is an unordered collection of unique items. This means two things: first, the items in a set do not have a defined order, and second, a set cannot contain duplicate elements. Sets are created using curly braces {} or the set() function. They are one of the primary mutable data types in python

Key Characteristics: 

  • Unordered: The items do not have a fixed position or index. 
  • Unique Elements: Each element in a set must be unique. If you try to add a duplicate, it will be ignored. 
  • Mutable: You can add or remove elements from a set. 
  • Highly Optimized for Membership Testing: Sets are extremely fast for checking if an element is present in the collection. 

When to use them: Sets are perfect when the uniqueness of items is important. Use them to remove duplicates from a list or to perform mathematical set operations like union, intersection, and difference. 

Python 
# Example of a set 
tags = {"python", "data", "code", "python"} # The duplicate "python" is ignored 
print(tags) # Output might be {'data', 'code', 'python'} (order not guaranteed) 
 
# Checking for membership is very fast 
print("python" in tags) # Output: True 
 
# Adding a new item 
tags.add("developer") 
print(tags) 
 

Also Read: 4 Built-in Data Structures in Python: Dictionaries, Lists, Sets, Tuples 

2. Dictionaries (dict) 

A dictionary is a collection of key-value pairs. Instead of accessing items by their position (index), you access them using a unique key. Dictionaries are incredibly flexible and are used to store related pieces of information. They are also mutable and are defined using curly braces {} with colons separating keys and values. 

Key Characteristics: 

  • Key-Value Pairs: Each item consists of a key and its corresponding value (e.g., "name": "Alice"). 
  • Keys are Unique and Immutable: Keys must be unique within a dictionary. Keys also must be of an immutable type (like strings, numbers, or tuples). 
  • Mutable: You can add, remove, or modify key-value pairs. 
  • Fast Lookups: Retrieving a value by its key is extremely fast. 
  • Ordered (Python 3.7+): In modern Python versions, dictionaries maintain the order in which items were inserted. 

When to use them: Dictionaries are the go-to data structure for storing structured information. Use them to represent real-world objects like a user profile ({'name': 'Bob', 'age': 30, 'city': 'New York'}), to store configuration settings, or to manage data returned from an API (like JSON). 

Python 
# Example of a dictionary 
student = { 
    "name": "John Doe", 
    "student_id": 12345, 
    "courses": ["Math", "Science", "History"] 
} 
print(student) 
 
# Accessing a value by its key 
print(student["name"]) # Output: John Doe 
 
# Adding a new key-value pair 
student["major"] = "Computer Science" 
print(student) 
 

Also Read: Sort Dictionary by Value Python 

Immutable vs Mutable Data Types in Python 

The table below summarizes the key differences, examples, and advantages of immutable and mutable data types in Python. 

Aspect 

Immutable Data Types 

Mutable Data Types 

Definition  Cannot be changed after creation. Any modification creates a new object.  Can be changed in place without creating a new object. 
Examples  int, float, str, tuple, frozenset  list, dict, set, bytearray 
Why It Matters  Supports hashing, ensures thread safety, prevents issues with mutable defaults in functions.  Allows in-place updates, saves memory for large data, offers flexibility for dynamic operations. 
Memory Behavior  Creates a new object on every modification.  Updates the same object in memory. 
Use Cases  Ideal for fixed data, dictionary keys, and concurrent programs.  Useful for data that changes frequently, like collections and caches. 
Pros  Safer for concurrency; Usable as dictionary keys; Predictable behavior  Faster updates and edits; Memory-efficient for large mutable structures; Flexible for dynamic data 
Cons  Higher memory usage due to object recreation; Not editable once created  Risk of unintended side effects; Unhashable (cannot be used as dict keys) 

Conclusion 

Mastering the seven fundamental python data types; Integers, Floats, Strings, Lists, Tuples, Sets, and Dictionaries, is essential for any aspiring Python developer. Each type serves a unique purpose, and understanding their characteristics, especially the distinction between mutable and immutable types, allows you to write more efficient, readable, and robust code. 

By choosing the right data type for the job, you make your program's logic clearer and prevent common errors. As you continue your Python journey, these data types will be the foundational tools you use every single day to build powerful and elegant applications. 

Discover top-rated Data Science courses that are tailored to enhance your expertise and open doors to exciting career opportunities.

Subscribe to upGrad's Newsletter

Join thousands of learners who receive useful tips

Promise we won't spam!

Explore our insightful Data Science articles that dive deep into industry trends and skills, helping you stay ahead in your career.

Master the essential Data Science skills with our curated courses, designed to equip you for the most in-demand roles in the industry.

Frequently Asked Questions (FAQs)

1. What are Python data types?

 Python data types define the kind of value a variable can hold. They determine how data is stored, manipulated, and accessed. Understanding Python data types helps you write efficient code, avoid errors, and choose the right type for different operations. 

2. Why are data types in Python important?

 Data types in Python are crucial for memory management, operation efficiency, and program correctness. Choosing the correct data type ensures proper computation, prevents type errors, and allows Python to handle dynamic typing effectively. 

3. What are the main categories of Python data types?

 Python data types are categorized as mutable and immutable. Immutable types cannot be changed after creation, while mutable types can. Examples include int, str, tuple for immutable, and list, dict, set for mutable types. 

4. What are immutable data types in Python?

 Immutable data types in Python cannot be modified once created. Common examples include int, float, str, tuple, and frozenset. Any modification creates a new object, ensuring safety in concurrent operations and hashable use in dictionaries. 

5. What are mutable data types in Python?

 Mutable data types in Python can be changed after creation. Examples are list, dict, set, and bytearray. They allow in-place updates, dynamic operations, and flexibility, but require careful handling to avoid unintended side effects. 

6. How do Python data types affect program performance?

 Data types in Python influence memory usage and execution speed. Immutable types may create new objects on modification, whereas mutable types update in place. Choosing the right type improves efficiency and avoids unnecessary copying or slow computations. 

7. What is the difference between mutable and immutable types in Python?

 Immutable types cannot be changed after creation, while mutable types can. Immutable types like tuple are safe for dictionary keys and concurrent use, while mutable types like list allow dynamic updates but may introduce side effects. 

8. Which Python data types are numeric?

 Numeric data types in Python include int for integers and float for decimal values. These types support arithmetic operations, comparisons, and conversions. They are immutable and essential for calculations and mathematical logic in programs. 

9. How are strings treated in Python data types?

 Strings (str) in Python are immutable sequences of characters. You can manipulate them using slicing, concatenation, or built-in methods like split and join. Modifying a string creates a new object, maintaining immutability principles. 

10. What are lists in Python data types?

 Lists are mutable, ordered collections that store multiple items. You can append, remove, or modify elements in place. Lists allow dynamic changes, indexing, and iteration, making them one of the most versatile Python data types. 

11. How do tuples differ from lists in Python?

 Tuples are immutable, while lists are mutable. Tuples provide fixed-size sequences, support hashing, and are safer for use as dictionary keys. Lists, by contrast, allow dynamic modifications, making them ideal for variable-length collections. 

12. What are dictionaries in Python data types?

 Dictionaries (dict) are mutable, unordered collections of key-value pairs. Keys must be immutable, values can be any type. They allow fast lookup, insertion, and deletion, making them useful for mapping and structured data representation. 

13. How are sets used in Python data types?

 Sets are mutable collections of unique elements, while frozenset is the immutable variant. Sets support union, intersection, and difference operations, making them ideal for handling distinct items and performing mathematical set operations. 

14. What is type conversion in Python data types?

 Type conversion or casting changes a value from one Python data type to another. For example, int() converts strings to integers. Proper conversion ensures accurate operations, avoids errors, and allows interoperability between different data types. 

15. How can I check Python data types?

 Use the type() function to identify a variable's data type and isinstance() to check if it belongs to a specific type. These functions help ensure correctness and avoid type-related errors in Python programs. 

16. Can mutable types be used as dictionary keys?

 No. Dictionary keys must be immutable because keys are hashed for quick lookup. Using mutable types like lists as keys raises a TypeError. Immutable types like str, tuple, or frozenset are safe for dictionary keys. 

17. Why is immutability important in Python data types?

 Immutability ensures data integrity, supports hashing, and prevents unintended side effects. Immutable types are safer for concurrent operations, dictionary keys, and predictable behavior, reducing bugs in Python programs. 

18. What are common pitfalls with mutable data types in Python?

 Mutable types can lead to unexpected behavior when modified unintentionally. Examples include using mutable defaults in functions or shared lists across objects. Proper copying and careful updates prevent such issues. 

19. How do Python data types impact function performance?

 Using mutable types may improve performance by avoiding object recreation, while immutable types may consume more memory for modifications. Choosing the right type optimizes speed, memory usage, and program stability. 

20. Where can I learn more about Python data types?

 Official Python documentation, Real Python, GeeksforGeeks, and Programiz provide comprehensive guides. They cover all Python data types, examples, mutable vs immutable differences, and best practices for coding efficiently in Python. 

Rohit Sharma

834 articles published

Rohit Sharma is the Head of Revenue & Programs (International), with over 8 years of experience in business analytics, EdTech, and program management. He holds an M.Tech from IIT Delhi and specializes...

Speak with Data Science Expert

+91

By submitting, I accept the T&C and
Privacy Policy

Start Your Career in Data Science Today

Top Resources

Recommended Programs

upGrad Logo

Certification

3 Months

Liverpool John Moores University Logo
bestseller

Liverpool John Moores University

MS in Data Science

Double Credentials

Master's Degree

17 Months

IIIT Bangalore logo
bestseller

The International Institute of Information Technology, Bangalore

Executive Diploma in DS & AI

360° Career Support

Executive PG Program

12 Months