Class 12 Computer Science – Python Lists (Quick Notes)
What is a List?
A list is a mutable, ordered collection used to store multiple values in a single variable.
Characteristics
1 Ordered (index-based)
2 Mutable (changeable)
3 Allows duplicate values
4 Can store different data types
Accessing Elements
Use index positions starting from 0. Negative index starts from -1 (last element).
Slicing
Syntax: list[start : stop : step]
Important List Methods
1 append(x): Adds x at the end
2 insert(i, x): Inserts x at index i
3 extend(list): Adds elements of another list
4 pop(): Removes last element
5 remove(x): Removes value x
6 sort(): Sorts the list
7 reverse(): Reverses the list
List vs Tuple
1 List is mutable, Tuple is immutable
2 List uses [ ], Tuple uses ( )
Common Board Questions
1 Define list and write its features.
2 Difference between append() and extend().
3 Write a program to find largest element in a list.