Lists allow duplicate values and are zero-indexed.
Question 2: What is a tuple?
Ans
A tuple is an ordered, immutable sequence. It is useful for fixed groups of values and can be used as a dictionary key when all contained values are hashable.
Example
python
point = (10, 20)
x, y = point
print(x, y)
Important Point
Tuple immutability does not recursively make contained mutable objects immutable.
Question 3: List vs tuple?
Ans
Lists are mutable and are suited to collections that change. Tuples are immutable and are useful for fixed records or values that should not be reassigned.
Example
python
items = [1, 2]
items.append(3)
point = (10, 20)
Important Point
Choose based on semantics, not on a blanket claim that tuples are always faster.
Question 4: What is a set?
Ans
A set is an unordered collection of unique hashable elements. It supports efficient average-case membership testing and mathematical set operations.
Example
python
skills = {"Java", "Python", "SQL"}
skills.add("Git")
print("Python" in skills)
Important Point
Set elements must be hashable.
Question 5: What is a frozenset?
Ans
A frozenset is an immutable set. Because it is immutable and hashable when its elements are hashable, it can itself be used as a dictionary key or set element.
Example
python
permissions = frozenset({"read", "write"})
print("read" in permissions)
Important Point
You cannot add or remove elements from a frozenset.
Question 6: What is a dictionary?
Ans
A dictionary stores key-value pairs and provides average-case constant-time lookup for hashable keys under normal conditions.
Keys must be hashable and unique; assigning an existing key replaces its value.
Question 7: Can dictionary keys be lists?
Ans
No. Lists are mutable and unhashable, so they cannot be dictionary keys. Immutable hashable alternatives such as tuples can be used when their elements are hashable.