Previous Up Next

5.43.8  Insert an element into a list or a string: insert

The insert command takes three arguments, a list (or string), and index, and an element.
insert returns the list (or string) with the element inserted into the position given by the index, with all other elements shifted to the right.
Input:

insert([3,4,2],2,5)

Output:

[3,4,5,2]

Input:

insert("342",2,"5")

Output:

"3452"

insert returns an error if the index is too large.
Input:

insert([3,4,2],4,5)

Output:

insert([3,4,2],4,5) Error: Invalid dimension

Previous Up Next