Lists are one of the most versatile data types in Python. They are used to store collections of items, which can be of different types and sizes.
Lists are created by placing items inside square brackets [], separated by commas.
my_list = [1, 2, 3, 4, 5] mixed_list = [1, "hello", True, 3.14]
Elements in a list can be accessed by their index. Indexing starts at 0 for the first element.
first_element = my_list[0] last_element = my_list[-1]
You can also access a subset of elements in a list using slicing.
subset = my_list[1:4] # Returns elements from index 1 to 3 subset = my_list[:3] # Returns elements from the beginning to index 2 subset = my_list[3:] # Returns elements from index 3 to the end