REVISION SUMMARY: Lists (NCERT Class 11 Computer Science)
[] and separated by commas; indexing starts at 0 (supports both positive and negative indices).+), repetition (*), membership (in / not in) and slicing.for loop (with or without range(len())) or a while loop.len(), append(), extend(), insert(), pop(), remove(), sort(), sorted(), etc.) allow creation, modification and manipulation of lists.list[i][j].list2 = list1 creates an alias (same object); distinct copies are made by slicing, list() or copy.copy().+ operator.* operator.in (returns True if present) or not in.list[start:end:step].list2 = list1) so both refer to the same list object.list() or copy.copy()) so that changes to one do not affect the other.```python
list1 = [2, 4, 6, 8, 10, 12] list2 = list() # empty list list3 = list("aeiou") # from sequence
list1 + list2 list1 * 3
'Red' in list1 'Cyan' not in list1
list1[2:6] list1[::2] list1[::-1]
for item in list1: print(item) for i in range(len(list1)): print(list1[i]) i = 0 while i < len(list1): print(list1[i]) i += 1 ```
Methods & Built-in Functions (general form + example)
python
len(list1) # returns length
list1.append(50) # appends single element at end
list1.extend([40,50]) # appends each element of argument list
list1.insert(2, 25) # inserts at index
list1.count(10) # returns occurrences
list1.index(20) # returns first index or ValueError
list1.remove(30) # removes first occurrence or ValueError
list1.pop(3) # removes & returns element at index (default last)
list1.reverse() # reverses in-place
list1.sort() # sorts in-place (ascending); sort(reverse=True) for descending
sorted(list1) # returns new sorted list
min(list1), max(list1), sum(list1)
List Traversal (for / while)
- Initialise list → use for item in list1 or for i in range(len(list1)) or while i < len(list1) with i += 1.
Linear Search (Program 9-5 style)
1. Accept list and search value.
2. Loop from 0 to len(list)-1.
3. If list[i] == num, return i.
4. If loop ends, return None.
Copying a List (three distinct methods)
- newList = oldList[:] (slicing)
- newList = list(oldList)
- import copy; newList = copy.copy(oldList)
IndexError: list index out of range when index exceeds length.TypeError: can only concatenate list (not "str") to list when using + with non-list.ValueError from index() or remove() when element is absent.append([50,60]) (adds list as single element) with extend([50,60]) (adds each element).sort() (in-place, returns None) instead of sorted() (returns new list) or vice-versa.list2 = list1 creates an independent copy (it creates an alias).list1[n-1] or list1[-n] gives last/first element when using len().remove() deletes only first occurrence).pop(i) or insert(pos, elem).A study aid reviewed by GFIS faculty — always verify with your textbook and teacher.