How To Append To A List In Python?

Use `list.append(item)` to add one item to the end of a list

Example: `my_list.append(4)`

Use `list.extend(iterable)` to add multiple items to the end of a list

Example: `my_list.extend([4, 5, 6])`

Use `list.insert(index, item)` to add an item at a specific position

Example: `my_list.insert(0, 1)`

Use `+=` to concatenate another list

Example: `my_list += [4, 5]`

Use slicing to append items at the end

Example: `my_list[len(my_list):] = [4, 5]`

Suggested for You

Trending Today