Chapter: Accountancy· 12th
Answer: A Python list is an ordered, mutable sequence that can hold items of any type, written inside square brackets.
Key features of a list:
- Ordered: items keep the order in which they are stored, and each has an index starting from 0. Negative indices count from the end (
L[-1]is the last item). - Mutable: items can be changed, added or removed after the list is created, e.g.
L[0] = 5,L.append(7),L.remove(5). - Heterogeneous: one list can hold different data types, e.g.
[10, "Ram", 45.5, True]. - Allows duplicates: the same value can appear more than once.
- Dynamic size: a list grows or shrinks as items are added or deleted.
- Supports slicing and operators:
L[1:4], concatenation with+, repetition with*, membership within. - Can be nested: a list can contain other lists, e.g.
[[1, 2], [3, 4]]. - Built-in methods:
append(),extend(),insert(),pop(),sort(),reverse(),count(),index(), and functions likelen(),max(),min().
marks = [78, 85, 92]
marks.append(66)
print(marks[0], marks[-1]) # 78 66