Junior — Middle
What is the purpose of the append function in working with data collections?
sobes.tech AI
Answer from AI
In Python, the append function is used to add a single element to the end of a list. This modifies the original list, extending it by one element.
Example:
my_list = [1, 2, 3]
my_list.append(4)
print(my_list) # Outputs: [1, 2, 3, 4]
Important: append adds exactly one element. If you need to add multiple elements from another collection, use extend.