A tuple is like a list that cannot be changed. That restriction is useful: it protects data from accidental change, lets tuples be used as dictionary keys, and makes them the natural way to group a few related values, such as a record or several values returned from a function.
Creating tuples
Form
Example
Note
With parentheses
t = ('a', 'b', 'c')
The usual style
Without parentheses
t = 'a', 'b', 'c'
The commas make the tuple
One item
t1 = ('a',)
The trailing comma is required; ('a') is just the string 'a'
Empty
() or tuple()
From an iterable
tuple("IGNOU")
('I', 'G', 'N', 'O', 'U')
Operations
Tuples support indexing, slicing, +, *, in, len(), min(), max(), sum(), sorted() (returns a list) and comparison. Comparison is lexicographic: elements are compared pair by pair until two differ, so (0, 1, 500000) < (0, 3, 4) is True because 1 < 3. Tuples have only two methods: count(x) and index(x).
Trying to change an item raises TypeError: 'tuple' object does not support item assignment. You can, however, build a new tuple: t = ('A',) + t[1:].
Immutability is shallow
A tuple’s slots cannot be changed, but if a slot holds a mutable object such as a list, that object can still change.
univ = ('du', 'jnu', ignou) where ignou is a list
univ: ( 'du' , 'jnu' , ● ) │ ▼ ['soe', 'soms', 'socis'] <- this list can still grow
Tuple assignment (unpacking)
A tuple (or any sequence) on the right can be unpacked into several names on the left: x, y = ['good', 'luck']. The number of names must equal the number of items. This gives Python’s one-line swap, a, b = b, a: the right side is packed into a tuple first, then unpacked.
Tuples versus lists
List
Tuple
Syntax
[1, 2]
(1, 2)
Mutable
Yes
No
Methods
Many
count, index
Can be a dictionary key or set item
No
Yes, if all its items are immutable
Typical use
A collection of similar items that changes
A fixed group of related values (a record, coordinates, several return values)
Speed and memory
Slightly more
Slightly less
Key takeaways
Tuples are ordered and immutable; the comma makes a tuple.
They support indexing, slicing, +, *, in, count() and index().
Unpacking assigns items to names; a, b = b, a swaps.
Use tuples for fixed records and as dictionary keys.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain how a, b = b, a swaps two values, and why no temporary variable is needed.
Show worked answer
Python evaluates the right side first, building the tuple (b, a) from the current values. Only then does it unpack the tuple into the names on the left, assigning the first item to a and the second to b. Because both old values are already saved inside the tuple before any assignment happens, neither value is lost, so no separate temporary variable is needed (the tuple acts as one).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-structures-and-control-statements-in-python/tuples/ to read this page.