Keshava Harshith Manikyala
PRO
2 months ago
Keshavacountry asked

What is the difference between List, Tuple, and Dictionary?

Kelish Rai
Expert
2 months ago
Kelish Rai answered

The key thing to note is that lists, tuples, and dictionaries are simply different ways to store data. Which one you choose depends on what you need your program to do.

That said, here are the major differences between them:

List: An ordered collection that can be changed (mutable).

my_list = [1, 2, 3]

my_list[0] = 10    # You can change items

print(my_list)    # Output: [10, 2, 3]

Tuple: Also ordered, but cannot be changed (immutable).

my_tuple = (1, 2, 3)

# my_tuple[0] = 10    # This would cause an error

print(my_tuple)    # Output: (1, 2, 3)

Dictionary: Stores data as key-value pairs, and you access values using keys.

my_dict = {"name": "Ali", "age": 25}

print(my_dict["name"])    # Output: Ali

my_dict["age"] = 26    # You can update values

So, lists and tuples store values by position — but only lists can be changed. Dictionaries store data using keys, which makes them great when you want to label and quickly access your data.

Let me know if you need more clarification on this.

Python
This question was asked as part of the Learn Python Basics course.