python list add at beginning 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 how to add a string to the beginning of a list

listexample['exampleone', 'examplethree']
listexample.insert(0, 'exampletwo')
print(listexample)
#prints ['exampletwo', 'exampleone', 'examplethree']
#Use the insert() method when you want to add data to the beginning or middle of a list. 
#Take note that the index to add the new element is the first parameter of the method.