📘 Lesson  ·  Lesson 80

List vs Tuple vs Set vs Dict

The Four Collections

💡 At a Glance

Python has four built-in collection types. Knowing when to use each is a very common interview question.

Comparison Table

TypeOrderedChangeableDuplicatesSyntax
ListYesYesYes[1, 2, 3]
TupleYesNoYes(1, 2, 3)
SetNoYesNo{1, 2, 3}
DictYes (3.7+)YesNo keys{"a": 1}

Example

Python
my_list = [1, 2, 2, 3]      # allows duplicates
my_tuple = (1, 2, 3)        # cannot change
my_set = {1, 2, 2, 3}       # removes duplicate -> {1,2,3}
my_dict = {"name": "Aman"}  # key-value pairs
print(my_set)
{1, 2, 3}

Summary

  • List = ordered, changeable, allows duplicates.
  • Tuple = ordered, fixed. Set = unordered, unique. Dict = 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.