Junior — Middle
What is the structure of the list data type in Python and how does it work?
sobes.tech AI
Answer from AI
In Python, a list is a mutable ordered collection of elements that can store objects of any type. It is implemented as a dynamic array, which provides fast access by index (O(1) operation) and relatively efficient appending of elements at the end.
Main features of list:
- Supports indexing and slicing.
- Allows storing duplicates and elements of different types.
- Mutable: elements can be added, removed, and modified.
Example usage:
my_list = [1, 'hello', 3.14]
my_list.append(42) # adding an element
print(my_list[1]) # outputs 'hello'
my_list[0] = 100 # changing the first element