1. Difference Between List and Tuple?

Lists and tuples are both sequence data types in Python that can store multiple items.
However, the key difference lies in their mutability and usage:

FeatureListTuple
MutabilityMutable (can be changed after creation)Immutable (cannot be changed once created)
SyntaxDefined using []Defined using ()
PerformanceSlower (due to mutability)Faster (due to immutability)
Use CaseSuitable for data that changesSuitable for fixed data
MethodsMany (e.g., append(), remove(), sort())Few (e.g., count(), index())

🧩 Example:

# List Example
my_list = [1, 2, 3]
my_list.append(4)  # Modifying the list
print("List:", my_list)

# Tuple Example
my_tuple = (1, 2, 3)
# my_tuple.append(4)  # ❌ Error: Tuples are immutable
print("Tuple:", my_tuple)

Output:

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top