Appending or prepending a value to a list in Python.
Append value
a = ["v1", "v2", "v3", "v4"] print a a.append("new val") print a
['v1', 'v2', 'v3', 'v4'] ['v1', 'v2', 'v3', 'v4', 'new val']
Env: Python 2.7.18
Prepend value
a = ["v1", "v2", "v3", "v4"] print a a.insert(0, "new val") print a a = ["new value2"] + a print a
['v1', 'v2', 'v3', 'v4'] ['new val', 'v1', 'v2', 'v3', 'v4'] ['new value2', 'new val', 'v1', 'v2', 'v3', 'v4']
Env: Python 2.7.18