Sobes.tech
Junior — Middle

Can you explain what a list data structure in Python is?

sobes.tech AI

Answer from AI

In Python, a list is a mutable ordered collection of elements that can contain objects of different types. Lists support indexing, slicing, adding, removing, and modifying elements.

Example of creating and using a list:

fruits = ['apple', 'banana', 'cherry']
fruits.append('orange')  # adding an element
print(fruits[1])          # outputs 'banana'
fruits[0] = 'pear'       # modifying an element
print(fruits)

Lists are widely used for storing and processing sequences of data due to their flexibility.