python lis append code example
Example 1: add something to list python
#append to list
lst = [1, 2, 3]
something = 4
lst.append(something)
#lst is now [1, 2, 3, 4]
Example 2: python list append
# Python list mutation, adding elements
history = ["when"]
# adds item to the end of a list
history.append("how")
# ["when", "how"]
# combine lists
history.extend( ["what", "why"] ) # works with tuples too
# or
history = history + ["what", "why"]
# ["when", "how", "what", "why"]
# insert at target position
history.insert(3, "where")
# ["when", "how, "what", "where", "why"]
#