Difference Between List And Tuple
Published on October 01 2023
In this tutorial, we will learn what is the difference between a list and a tuple in Python and understand each in detail. This tutorial is part of Python's top 25 most commonly asked interview questions.
List vs Tuple
LIST |
TUPLE |
Lists are mutable, i.e., they can be edited. |
Tuples are immutable (they are lists that cannot be edited - remain constant). |
Lists are slower than tuples. |
Tuples are faster than lists. |
Lists consume a lot of memory. |
Tuples consume less memory when compared to lists. |
It cannot be used as a key in a dictionary. |
Can be used as a dictionary key. |
Lists are less reliable in terms of errors as unexpected changes are more likely to occur. |
Tuples are more reliable as it is hard for any unexpected change to occur. |
Syntax: data_list = [1, ‘The Programming Portal’, 'India', 9999] |
Syntax: data_tup = (1, ‘The Programming Portal’, 'India', 9999) |
Why is tuple faster?
- Tuple is stored in a single block of memory whereas List is stored in two blocks of memory.
- One is fixed sized with all the Python object information and the other is variable sized for storing data.
- Tuples are immutable, It doesn't require extra space to store new objects.
To know about it, please refer to the official documentation website - official website.
Next Tutorial
- What Is Python, Its Benefits And Features?
- What Is Pickling And Unpickling In Python?
- Memory Management In Python
- What Is The __Init__ In Python?
- Difference Between List And Tuple
- What Is The Self Keyword In Python?
- What Is The Lambda Function In Python?
- What Is A Break, Continue, And Pass Statement In Python?
- What Are The Common Built-In Data Types In Python?
- What Is The Difference Between .Py And .Pyc Files In Python?
- What Are Decorators In Python?
- What Is Slicing In Python?
- What Are Negative Indexes In Python?
- What Is List And Dictionary Comprehension In Python?
- What Is A Docstring In Python?
- What Are Python Iterators?
- What Are *Args And **Kwargs In Python And How To Use Them?
- What Is The Pythonpath Variable In Python?
- What Are Namespaces In Python?
- What Is Pep8 (Python Enhancement Proposals) In Python?
- What Is The Split(), Join(), Sub(), And Subn() Method In Python?
- What Are Modules And Packages In Python?
- What Is Scope Resolution In Python?
- Is Python Compiled Or Interpreted Language?
- What Are Generators In Python?