File size: 488 Bytes
625e9e8
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Python Lists

Lists in Python are ordered, mutable sequences. You can create a list using square brackets:
my_list = [1, 2, 3, 4, 5]

Adding Items:
- Use append() to add one item: my_list.append(6)
- Use extend() to add multiple items: my_list.extend([7, 8, 9])
- Use insert() to add at specific position: my_list.insert(0, 0)

Accessing Items:
- Use indexing: my_list[0] gets first item
- Use slicing: my_list[1:3] gets items 1 and 2
- Negative indexing works: my_list[-1] gets last item