# Lists in Python
# Lists in Python
Lists are one of Python's most versatile and commonly used data structures. They are ordered,
mutable collections that can hold elements of different data types.
## Characteristics of Lists
## Creating Lists
```python
# Empty list
empty_list = []
## Accessing Elements
```python
fruits = ['apple', 'banana', 'cherry', 'date']
# Slicing [start:stop:step]
print(fruits[1:3]) # ['banana', 'cherry']
print(fruits[::2]) # ['apple', 'cherry']
print(fruits[::-1]) # ['date', 'cherry', 'banana', 'apple'] (reverse)
```
## Modifying Lists
```python
colors = ['red', 'green', 'blue']
# Remove elements
colors.remove('yellow') # Removes first occurrence
popped = colors.pop(2) # Removes and returns item at index 2
del colors[0] # Removes item at index 0
```
## Common Operations
```python
a = [1, 2, 3]
b = [4, 5, 6]
# Concatenation
combined = a + b # [1, 2, 3, 4, 5, 6]
# Repetition
repeated = a * 2 # [1, 2, 3, 1, 2, 3]
# Membership testing
print(2 in a) # True
print(7 not in a) # True
# Length
print(len(a)) #3
```
## List Methods
## List Comprehensions
```python
# Squares of numbers 0-9
squares = [x**2 for x in range(10)]
# Nested comprehension
matrix = [[i*j for j in range(3)] for i in range(4)]
```
Lists are fundamental to Python programming and understanding them thoroughly will make you
more effective at working with Python data structures.