Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
📘 Lesson  ·  Lesson 48

List vs Tuple vs Set vs Dictionary in Python

In this lesson: Difference between list, tuple, set and dictionary in Python — mutability, order, duplicates — comparison table. In Hindi & English.

Four ways to store data

Python has four main built-in ways to store a collection of data: list, tuple, set and dictionary. They differ in whether they can change, whether they keep order, and whether they allow duplicates. Picking the right one makes your code cleaner and faster.

💡 Quick memory aid: list [] changeable, tuple () fixed, set {} unique, dict {} key:value.

List

An ordered, changeable collection — the most common one.

fruits = ["apple", "mango", "banana"]
fruits.append("kiwi")     # add
fruits[0] = "orange"      # change
print(fruits)
['orange', 'mango', 'banana', 'kiwi']

Lists use square brackets [], keep their order, allow duplicates, and can be changed freely. Use them for data that grows or changes.

Tuple

An ordered collection that cannot be changed after creation.

point = (10, 20)
print(point[0])          # read is fine -> 10
# point[0] = 5           # ERROR: tuples are immutable
10

Tuples use round brackets (). They keep order and allow duplicates, but are fixed. Use them for data that should not change, like coordinates or settings.

Set

An unordered collection of only unique values.

nums = {1, 2, 2, 3, 3, 3}
print(nums)              # duplicates dropped
nums.add(4)
print(4 in nums)         # fast membership check
{1, 2, 3}
True

Sets use curly braces {} with just values. They drop duplicates automatically and are great for uniqueness and fast "is it in here?" checks — but they keep no order.

Dictionary

Stores key-value pairs, so you look up a value by its key.

student = {"name": "Aman", "marks": 88}
print(student["name"])    # Aman
student["class"] = 12     # add a pair
print(student)
Aman
{'name': 'Aman', 'marks': 88, 'class': 12}

Dictionaries use curly braces with key: value pairs. Use them when each value needs a meaningful label, like a record of fields.

Quick comparison

TypeBracketsChangeable?Order?Duplicates?
list[ ]YesYesYes
tuple( )NoYesYes
set{ }YesNoNo
dict{ key: val }YesYesKeys unique

Common mistakes

  • Trying to change a tuple. Tuples are immutable — use a list if you need to edit.
  • Relying on set order. Sets have no order; do not expect items in sequence.
  • Using a list when you need uniqueness. A set removes duplicates for free.
  • Confusing set and dict braces. Both use {}; a dict has key: value, a set has only values.

Summary

  • List [ ] — ordered, changeable, allows duplicates.
  • Tuple ( ) — ordered, fixed (immutable).
  • Set { } — unordered, unique values only.
  • Dict { key: value } — labelled key-value pairs.
  • Choose by whether you need to change data, keep order, or ensure uniqueness.

Next, dive into list comprehension, or loop over any of these with Python loops.

Frequently Asked Questions

What is the main difference between a list and a tuple?
A list is mutable — you can change, add or remove items. A tuple is immutable — once created, it cannot be changed. Use a list for data that changes, and a tuple for fixed data you want to protect.
When should I use a set?
Use a set when you need only unique values and do not care about order — like removing duplicates from a list, or quickly checking if an item exists. Sets automatically drop duplicates.
What is a dictionary used for?
A dictionary stores data as key-value pairs, like a real dictionary of word and meaning. Use it when each value needs a label to look it up by, such as a student's name mapped to their marks.
Which ones keep their order?
Lists, tuples and dictionaries keep insertion order. Sets do not keep any order, so you should not rely on the order of items in a set.
Which brackets does each use?
List uses square brackets [], tuple uses round brackets (), and both set and dict use curly braces {} — a set has just values, while a dict has key: value pairs.
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicMap, Filter, Reduce Your progress: 48 / 66 (73%) · Lesson 49 / 66 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free