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 List vs Tuple: What's the Difference?

Python List vs Tuple - Complete Comparison

Learn the key differences between Python lists and tuples and when to use each.

Created by Sankalan Data Tech Team Verified
Data Engineers, Analysts, Scientists & Trainers
Created by experienced Python developers, data engineers, and data scientists to make programming easy through practical examples, real-world experience, and clear explanations.
On this page:
  • What's the Difference?
  • Mutability: The Big Difference
  • Syntax: Square Brackets vs Parentheses
  • Performance and Memory
  • Available Methods
  • Tuples as Dictionary Keys
  • When to Use Each
  • Quick Summary Table
  • Common Mistakes
  • Try It Yourself
  • Quiz
  • FAQ
Share this tutorial:
Twitter LinkedIn Facebook WhatsApp Reddit Telegram Email Copy Link
What You'll Learn Here
  • Mutability — lists can change, tuples can't
  • Syntax — square brackets vs parentheses
  • Performance — which one is faster
  • Memory — which one uses less space
  • Methods — what you can do with each
  • When to use — choosing the right one

What's the Difference?

If you're learning Python, you've probably wondered: "What's the difference between a list and a tuple?" They look similar, they work similarly, but they're not the same.

The short answer is: lists can change, tuples cannot. But there's more to it than that. Let's explore all the differences so you know exactly when to use each one.

💡 Here's the thing: The choice between list and tuple isn't just about mutability. It affects performance, memory usage, and even what you can do with your data.

Mutability: The Big Difference

1

Lists Can Change, Tuples Can't

This is the most important difference. A list is mutable — you can add, remove, or change elements. A tuple is immutable — once created, it stays the same forever.

# List (mutable)
my_list = [1, 2, 3]
my_list[0] = 10    # Works
my_list.append(4)  # Works
my_list.remove(2)  # Works
print(my_list)     # [10, 3, 4]

# Tuple (immutable)
my_tuple = (1, 2, 3)
# my_tuple[0] = 10   # TypeError! Can't change
# my_tuple.append(4) # AttributeError! No append
# my_tuple.remove(2) # AttributeError! No remove
print(my_tuple)      # (1, 2, 3)

# Why it matters:
# Lists are great when your data might change
# Tuples are great when your data should stay fixed

What this means for you:

  • Lists — flexible, but can be accidentally modified
  • Tuples — locked, safe from accidental changes
  • Tuples protect your data from bugs

Quick Check: What happens if you try to change a tuple? (Answer: TypeError)

Syntax: Square Brackets vs Parentheses

2

How You Write Them

Lists use square brackets []. Tuples use parentheses (). It's a small difference, but it matters.

# List — square brackets
my_list = [1, 2, 3, 4, 5]
print(type(my_list))  # <class 'list'>

# Tuple — parentheses
my_tuple = (1, 2, 3, 4, 5)
print(type(my_tuple)) # <class 'tuple'>

# Single-element trick
single_list = [10]     # List with one item
single_tuple = (10,)   # Tuple with one item (notice the comma!)
print(type(single_list))   # <class 'list'>
print(type(single_tuple))  # <class 'tuple'>

# Without the comma, it's not a tuple
not_a_tuple = (10)    # This is just an integer!
print(type(not_a_tuple)) # <class 'int'>

Quick tip:

  • Lists use [] — easy to remember because they're "open" to change
  • Tuples use () — think of parentheses as "sealing" the data
  • Don't forget the comma for single-element tuples!

Quick Check: What happens if you write (10) without a comma? (Answer: It's an integer, not a tuple)

Performance and Memory

3

Tuples Are Faster and Lighter

Because tuples can't change, Python can make them smaller and faster. They use less memory and are quicker to access.

import sys
import time

# Memory usage comparison
my_list = [1, 2, 3, 4, 5]
my_tuple = (1, 2, 3, 4, 5)

print(f"List size: {sys.getsizeof(my_list)} bytes")
print(f"Tuple size: {sys.getsizeof(my_tuple)} bytes")

# Output example:
# List size: 120 bytes
# Tuple size: 80 bytes

# Speed comparison (creating)
start = time.time()
for _ in range(1000000):
    my_list = [1, 2, 3, 4, 5]
list_time = time.time() - start

start = time.time()
for _ in range(1000000):
    my_tuple = (1, 2, 3, 4, 5)
tuple_time = time.time() - start

print(f"List creation time: {list_time:.4f}s")
print(f"Tuple creation time: {tuple_time:.4f}s")

# Tuples are usually faster!

Performance summary:

  • Tuples use less memory
  • Tuples are faster to create
  • Tuples are faster to access
  • For large amounts of data, this adds up!

Quick Check: Which uses less memory: list or tuple? (Answer: Tuple)

Available Methods

4

What You Can Do With Each

Lists have many methods for modifying data. Tuples have only a few methods for reading data.

# List methods (many!)
my_list = [1, 2, 3]
my_list.append(4)      # Adds element
my_list.insert(1, 10)  # Inserts at position
my_list.pop()          # Removes last
my_list.remove(2)      # Removes by value
my_list.sort()         # Sorts
my_list.reverse()      # Reverses
print(my_list)         # [1, 10, 3, 4]

# Tuple methods (only two!)
my_tuple = (1, 2, 3)
print(my_tuple.count(2))  # 1 — how many times 2 appears
print(my_tuple.index(3))  # 2 — position of 3

# That's it! No append, no remove, no sort
# dir(my_tuple) shows only count and index

Methods available:

  • Lists — append, insert, pop, remove, sort, reverse, extend, clear, copy
  • Tuples — count, index
  • Tuples have fewer methods because they can't change

Quick Check: How many methods does a tuple have? (Answer: Two — count and index)

Tuples as Dictionary Keys

5

Tuples Can Be Keys, Lists Cannot

Dictionary keys must be immutable. Tuples are immutable, so they work. Lists are mutable, so they don't.

# Tuple as dictionary key — works!
coordinates = {}
coordinates[(10, 20)] = "Point A"
coordinates[(30, 40)] = "Point B"
print(coordinates)  # {(10, 20): 'Point A', (30, 40): 'Point B'}

# List as dictionary key — TypeError!
# coordinates[[10, 20]] = "Point A"  # TypeError: unhashable type: 'list'

# Why this matters:
# This is a common interview question!
# "Can you use a list as a dictionary key?" -> NO
# "Can you use a tuple as a dictionary key?" -> YES

Key point:

  • Dictionary keys must be hashable
  • Tuples are hashable (if they contain hashable items)
  • Lists are not hashable
  • This is a big reason to use tuples

Quick Check: Can a tuple be a dictionary key? (Answer: Yes — tuples are immutable)

When to Use Each

6

Which One Should You Choose?

# Use lists when:
# 1. Your data needs to change
scores = [85, 92, 78]
scores.append(90)  # Add new score

# 2. You don't know how many items you'll have
items = []
items.append("apple")  # Adding as you go

# 3. You need to sort or reorder
names = ["Charlie", "Alice", "Bob"]
names.sort()

# 4. You need to remove items
tasks = ["write", "read", "edit"]
tasks.remove("read")  # Remove completed task

# Use tuples when:
# 1. Your data should never change
DAYS_OF_WEEK = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

# 2. You're returning multiple values from a function
def get_user():
    return "Alice", 25, "Engineer"  # Returns a tuple

# 3. You need a dictionary key
coordinates = {(10, 20): "Point A"}

# 4. Your data is fixed and known
RGB_RED = (255, 0, 0)
RGB_GREEN = (0, 255, 0)

Simple rule of thumb:

  • Use lists — when your data might change
  • Use tuples — when your data won't change
  • When in doubt, ask: "Will this change?"

Quick Summary Table

7
Feature List Tuple
Mutability Mutable (can change) ✅ Immutable (cannot change) ❌
Syntax Square brackets [] Parentheses ()
Memory Larger Smaller ✅
Speed Slower Faster ✅
Methods Many (append, pop, sort, etc.) Only 2 (count, index)
Dictionary Key ❌ No ✅ Yes
Best For Data that changes Data that stays fixed

Common Mistakes

8

Things to Watch Out For

Forgetting the Comma in Single-Element Tuples

# WRONG — this is an integer, not a tuple!
not_a_tuple = (10)
print(type(not_a_tuple))  # <class 'int'>

# CORRECT — comma makes it a tuple
correct_tuple = (10,)
print(type(correct_tuple))  # <class 'tuple'>

Using Tuple When You Need to Change Data

# WRONG — trying to change a tuple
my_tuple = (1, 2, 3)
# my_tuple[0] = 10  # TypeError!

# CORRECT — use a list if you need to change
my_list = [1, 2, 3]
my_list[0] = 10  # Works!

Using List When You Need a Dictionary Key

# WRONG — list as dictionary key
my_dict = {}
# my_dict[[1, 2]] = "value"  # TypeError!

# CORRECT — use a tuple
my_dict[(1, 2)] = "value"  # Works!

Quick Check: What's the most common mistake with tuples? (Answer: Forgetting the comma for single-element tuples)

Try It Yourself

Compare lists and tuples in the editor below. Change the code and see what happens.

Loading Pyodide... 0%
Python Code Editor
========================================
LIST VS TUPLE COMPARISON
========================================

List: [1, 2, 3, 4, 5]
Tuple: (1, 2, 3, 4, 5)

1. MUTABILITY
List can change: my_list[0] = 10
List after change: [10, 2, 3, 4, 5]
Tuple cannot change: try my_tuple[0] = 10

2. MEMORY USAGE
List size: 120 bytes
Tuple size: 80 bytes

3. AVAILABLE METHODS
List methods: append, pop, sort, remove, insert, reverse, extend, clear, copy
Tuple methods: count, index

4. DICTIONARY KEYS
Tuple as key: {(1, 2): 'This works!'}

5. WHEN TO USE
Use LIST when: data changes, ordering matters, you need many methods
Use TUPLE when: data stays fixed, memory matters, need dictionary keys

List vs Tuple comparison complete!
🏆

You've Got It!

You now understand the key differences between lists and tuples — mutability, syntax, performance, methods, and when to use each. This is a common interview question, so you're ready!

Quick Quiz

Test what you've learned:

1. What is the main difference between a list and a tuple?
2. What is the correct way to create a single-element tuple?
3. Which one can be used as a dictionary key?
4. Which uses less memory?
5. How many methods does a tuple have?

Frequently Asked Questions

Which is faster: list or tuple? ▼

Tuples are generally faster because they are simpler. They don't have to handle changes, so Python can optimize them better.

Can I convert a list to a tuple? ▼

Yes! Use tuple(list) to convert a list to a tuple. Use list(tuple) to convert a tuple to a list.

Can I change a tuple by converting it to a list? ▼

Yes, but you're creating a new list, not changing the original tuple. The tuple itself stays immutable.

Why would I use a tuple instead of a list? ▼

Use tuples when your data should never change, when memory is important, when you need a dictionary key, or when you want to protect your data from accidental changes.

Are tuples always faster than lists? ▼

Generally yes, but the difference is small for small data. For large data or many operations, the difference can be significant.

What's a common interview question about lists and tuples? ▼

The most common is: "What's the difference between a list and a tuple?" Answer: Lists are mutable, tuples are immutable. Followed by: "Can you use a list as a dictionary key?" Answer: No, but you can use a tuple.

Where to Go From Here

Now that you understand lists and tuples, check out these related topics:

List vs Set

Compare lists with sets for unique elements.

Learn More →

List vs Dictionary

Compare lists with dictionaries for key-value data.

Learn More →

Tuple vs Set

Compare tuples with sets for unique data.

Learn More →
Interview Resources
  • Python Syntax & Variables Interview Questions
  • Top SQL Interview Questions & Answers
  • SQL Joins: Displaying Data from Multiple Tables FAQ
Previous: Dictionary Assignments Next: List vs Set →