python push to front of list code example

Example 1: append to front of list python

var = 7
array = [1,2,3,4,5,6]
array.insert(0,var)
print(array)
# [7, 1, 2, 3, 4, 5, 6]

Example 2: python list add first

# list.insert(before, value)
list = ["a", "b"]
list.insert(0, "c")
print(list)     # ['c', 'a', 'b']

Example 3: python add to start of list

>>>var=7
>>>array = [1,2,3,4,5,6]
>>>array.insert(0,var)
>>>array
[7, 1, 2, 3, 4, 5, 6]

Example 4: how to append to front of the list using def method in python 3

['bee', 'moth']
['bee', 'moth', 'ant', 'fly']

Example 5: how to append to front of the list using def method in python 3

['bee', 'moth']
['ant', 'bee', 'moth']
['ant', 'bee', 'fly', 'moth']