2.6.1.5 List Operations
Python Programming
Lists also support various operations, such as slicing and concatenation.
Example: Slice a portion of the list and concatenate it with another list.
python
numbers = [1, 2, 3, 4, 5]
slice = numbers [1:4] # Gets items from index 1 to 3
extra_numbers = [6, 7]
combined = slice + extra_numbers
print(combined)
# Output : [2, 3, 4, 6, 7]Explanation: The code slices the 'numbers' list from index 1 to 3, combines it with 'extra_numbers', and prints the resulting list '[2, 3, 4, 6. 7]'.