ReplacePart

WMA link


ReplacePart[expr, i -> new]

replaces part i in expr with new.

ReplacePart[expr, {{i, j} -> $e_1$, {k, l} -> $e_2$}]

replaces parts i and j with $e_1$, and parts k and l with $e_2$.

Delayed rules are evaluated once for each replacement:

Non-existing parts are simply ignored:

You can replace heads by replacing part 0:

(This is equivalent to Apply.)

Negative part numbers count from the end:

PrependTo
Rest