Python Revision: Class 12 CS (CBSE)
LISTS (Mutable, Ordered)
- len(list): Number of elements
- [Link](x): Add x at end
- [Link](i, x): Insert x at index i
- [Link](x): Remove first x
- [Link](): Remove last element
- [Link](i): Remove at index i
- [Link](): Sort in ascending order
- [Link](): Reverse in place
- [Link](x): Index of x
- [Link](x): Count of x
- del list[i]: Delete element at index i
- [Link](): Empty the list
STRINGS (Immutable, Ordered)
- len(s): Length of string
- [Link](), [Link](), [Link]()
- [Link](): Remove spaces
- [Link]('x'): Index of 'x'
- [Link]('x'): Count 'x'
- [Link]('a','b'): Replace a with b
- [Link]('H'), [Link]('o')
- [Link](): Split at spaces
- ' '.join(list): Join list into string
TUPLES (Immutable, Ordered)
- len(t): Length
- [Link](x): Index of x
- [Link](x): Count of x
- list(t): Convert to list
- tuple(list): Convert to tuple
DICTIONARIES (Mutable, Key-Value)
- len(d): Number of items
- [Link](), [Link](), [Link]()
- [Link]('key'): Safe access
- d['key']: Direct access
- d['key'] = value: Add/update key
- [Link]('key'): Remove key
- [Link]({'k':v}): Add/update multiple
- [Link](): Empty dictionary
COMMON BUILT-IN FUNCTIONS
Python Revision: Class 12 CS (CBSE)
- type(x), id(x): Type and memory
- max(list), min(list), sum(list)
- sorted(list): New sorted list
- range(n): 0 to n-1
- enumerate(list): Index with value
- zip(list1, list2): Pairwise tuples