Explanation: In Python, both append() and extend() methods are used to add eleme
Explanation: In Python, both append() and extend() methods are used to add elements to a list, but they behave differently:
append(): Adds its argument as a single element to the end of the list. If you pass a list as an argument to append(), it will be added as a nested list.
Example:
my_list = [1, 2, 3]my_list.append(4)
print(my_list) # Output: [1, 2, 3, 4]
extend(): Iterates over its argument (which should be an iterable, typically a list) and adds each element to the end of the list. It effectively flattens the iterable.
Example:
my_list = [1, 2, 3]
my_list.extend([4, 5, 6])
print(my_list) # Output: [1, 2, 3, 4, 5, 6]
In summary, append() adds one element to the list, while extend() adds elements from an iterable to the li
