Yes, negative indexing can be used with lists in Python, just like with strings. It allows you to access elements from the end of the list.
Example:
For a list my_list = [10, 20, 30, 40, 50]:
my_list[0]gives10(first element)my_list[1]gives20(second element)my_list[-1]gives50(last element)my_list[-2]gives40(second last element)
Benefits:
- Convenience: Easily access the last elements without needing to calculate the length of the list.
- Flexibility: Works the same way for any list size.
If you have more questions or need further examples, feel free to ask!
