Difference between revisions of "Insert"
Jump to navigation
Jump to search
(Created page with "<c>insert</c> inserts a new element into a string or list. See also: remove === Arguments === {| class="wikitable" |- ! Parameter Name !! Default Value !! Meaning |- |...") |
m |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | <c>insert</c> inserts a new element into a string or list. | + | <c>insert</c> inserts a new element into a [[string]] or [[list]]. |
− | See also: [[remove]] | + | See also: [[push]]; [[remove]] |
=== Arguments === | === Arguments === | ||
Line 26: | Line 26: | ||
[[Category:List Methods]] | [[Category:List Methods]] | ||
[[Category:String Methods]] | [[Category:String Methods]] | ||
− | |||
− |
Latest revision as of 23:20, 30 July 2022
insert
inserts a new element into a string or list.
Arguments
Parameter Name | Default Value | Meaning |
---|---|---|
self | string or list | sequence to insert into |
index | number | position at which to insert the new item |
value | any | element to insert at the specified index |
Usage Notes
In the case of a list, the list is both modified in place and returned. Strings are immutable, so in that case the original string is unchanged, but a new string is returned with the value inserted.
Example
"Hello".insert(2, 42) // returns "He42llo"