This past week at Blockfuse Labs, under Mr. Dimka’s guidance, we focused on Python lists. We discovered their importance in organizing and manipulating data.
A Python list is a changeable collection that can hold various types of items, including strings, integers, booleans, and other lists.
```python
mixed_list = ["Elkanah", 22, True, 3.14]
```
**Accessing List Items**
Python uses zero-based indexing, meaning the first item is at index 0. Negative indexing allows access to elements from the end of the list.
```python
names = ["Dre", "", "Elkanah", "NVM", "Quan"]
print(names[0])
print(names[2])
print(names[-1])
```
We add items with `append()` and `insert()`.
```python
names = ["Dre", "", "Elkanah", "NVM", "Quan"]
names.append("Julius")
names.insert(1, "Mildred")
```
**Slicing a List**
You can get portions of a list using slicing.
```python
numbers = [1, 2, 3, 4, 5, 6]
print(numbers[1:4])
print(numbers[:3])
print(numbers[3:])
```
Learning to use list methods effectively improves code readability and saves time. Thanks to Mr. Dimka's practical examples and clear explanations, we not only learned how lists work but also understood their significance and why they matter.